apptask: delete app dir files when restoring

also, better deleteAppDir logs
This commit is contained in:
Girish Ramakrishnan
2025-08-22 19:31:32 +02:00
parent 074977c58e
commit 3b38440385

View File

@@ -125,16 +125,22 @@ async function deleteAppDir(app, options) {
const resolvedAppDataDir = stat.isSymbolicLink() ? safe.fs.readlinkSync(appDataDir) : appDataDir;
debug(`deleteAppDir - removing files in ${resolvedAppDataDir}`);
if (safe.fs.existsSync(resolvedAppDataDir)) {
const entries = safe.fs.readdirSync(resolvedAppDataDir);
if (!entries) throw new BoxError(BoxError.FS_ERROR, `Error listing ${resolvedAppDataDir}: ${safe.error.message}`);
// remove only files. directories inside app dir are currently volumes managed by the addons
// we cannot delete those dirs anyway because of perms
entries.forEach(function (entry) {
const stat = safe.fs.statSync(path.join(resolvedAppDataDir, entry));
if (stat && !stat.isDirectory()) safe.fs.unlinkSync(path.join(resolvedAppDataDir, entry));
});
// remove only files. any directories inside app dir are currently volumes managed by the addons
// besides, we cannot delete those dirs anyway because of perms
for (const entry of entries) {
const fullPath = path.join(resolvedAppDataDir, entry);
const stat = safe.fs.statSync(fullPath);
if (stat && !stat.isDirectory()) {
safe.fs.unlinkSync(fullPath);
debug(`deleteAppDir - ${fullPath} ${safe.error?.message || ''}`);
}
}
}
// if this fails, it's probably because the localstorage/redis addons have not cleaned up properly
@@ -286,7 +292,7 @@ async function installCommand(app, args, progressCallback) {
}
await services.teardownAddons(app, addonsToRemove);
if (!restoreConfig || restoreConfig.remotePath) { // in-place import should not delete data dir
if (!restoreConfig || restoreConfig.remotePath || restoreConfig.backupId) { // install/import/restore but not in-place import should delete data dir
await deleteAppDir(app, { removeDirectory: false }); // do not remove any symlinked appdata dir
}