refactor(speech): remove each model folder's leftovers in one loop on delete

This commit is contained in:
Kelvin Amoaba
2026-11-11 05:53:34 +00:00
parent 3348b8571b
commit 546bbfcbe5
+8 -12
View File
@@ -239,21 +239,17 @@ export class ModelManager extends SpeechModelDownloadTransport {
this.cancelDownload(modelId)
// A swap already under way ignores cancel; deleting mid-swap could race its restore.
await download?.settled
const modelDir = this.getModelDir(modelId)
if (existsSync(modelDir)) {
await rm(modelDir, { recursive: true, force: true })
}
await rm(`${modelDir}.partial`, { recursive: true, force: true })
await rm(previousSpeechModelDir(modelDir), { recursive: true, force: true })
await rm(join(this.modelsDir, `${modelId}.tar.bz2`), { force: true })
// Remove the migration source too or next launch resurrects the model.
const modelDirs = [this.getModelDir(modelId)]
if (this.migrationSourceDir) {
const sourceModelDir = this.getSafeModelDir(modelId, this.migrationSourceDir)
if (existsSync(sourceModelDir)) {
await rm(sourceModelDir, { recursive: true, force: true })
}
await rm(previousSpeechModelDir(sourceModelDir), { recursive: true, force: true })
modelDirs.push(this.getSafeModelDir(modelId, this.migrationSourceDir))
}
for (const modelDir of modelDirs) {
for (const path of [modelDir, `${modelDir}.partial`, previousSpeechModelDir(modelDir)]) {
await rm(path, { recursive: true, force: true })
}
}
await rm(join(this.modelsDir, `${modelId}.tar.bz2`), { force: true })
this.modelStates.delete(modelId)
}