If app.dataDir is set, first unmount from sftp before deleting on uninstall

This commit is contained in:
Johannes Zellner
2020-07-29 15:02:30 +02:00
parent f511a610b5
commit e1718c4e8d
2 changed files with 22 additions and 7 deletions

View File

@@ -743,7 +743,7 @@ function migrateDataDir(app, args, progressCallback, callback) {
}
// We do this after the app has the new data commited to the database
sftp.rebuild(function (error) {
sftp.rebuild({}, function (error) {
if (error) console.error('Failed to rebuild sftp addon:', error);
callback();
});
@@ -984,16 +984,22 @@ function uninstall(app, args, progressCallback, callback) {
progressCallback.bind(null, { percent: 30, message: 'Teardown addons' }),
addons.teardownAddons.bind(null, app, app.manifest.addons),
progressCallback.bind(null, { percent: 40, message: 'Deleting app data directory' }),
progressCallback.bind(null, { percent: 40, message: 'Remove sftp addon binding' }),
function (callback) {
if (!app.dataDir) return callback();
sftp.rebuild({ ignoredDataDirs: [ app.dataDir ] }, callback);
},
progressCallback.bind(null, { percent: 50, message: 'Deleting app data directory' }),
deleteAppDir.bind(null, app, { removeDirectory: true }),
progressCallback.bind(null, { percent: 50, message: 'Deleting image' }),
progressCallback.bind(null, { percent: 60, message: 'Deleting image' }),
docker.deleteImage.bind(null, app.manifest),
progressCallback.bind(null, { percent: 60, message: 'Unregistering domains' }),
progressCallback.bind(null, { percent: 70, message: 'Unregistering domains' }),
unregisterSubdomains.bind(null, app, [ { subdomain: app.location, domain: app.domain } ].concat(app.alternateDomains)),
progressCallback.bind(null, { percent: 70, message: 'Cleanup icon' }),
progressCallback.bind(null, { percent: 80, message: 'Cleanup icon' }),
removeIcon.bind(null, app),
progressCallback.bind(null, { percent: 90, message: 'Cleanup logs' }),

View File

@@ -19,12 +19,16 @@ function startSftp(existingInfra, callback) {
if (existingInfra.version === infra.version && infra.images.sftp.tag === existingInfra.images.sftp.tag) return callback();
rebuild(callback);
rebuild({}, callback);
}
function rebuild(callback) {
// options only supports ignoredDataDirs = [ pathString ]
function rebuild(options, callback) {
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof callback, 'function');
if (options.ignoredDataDirs) assert(Array.isArray(options.ignoredDataDirs), 'Expecting ignoredDataDirs to be an array');
debug('rebuilding container');
const tag = infra.images.sftp.tag;
@@ -37,6 +41,11 @@ function rebuild(callback) {
result.forEach(function (app) {
if (!app.dataDir) return;
if (options.ignoredDataDirs && options.ignoredDataDirs.indexOf(app.dataDir) !== -1) {
debug(`Ignoring dataDir ${app.dataDir}`);
return;
}
dataDirs.push({
hostDir: app.dataDir,
// /data is required since this is where the localstorage data would be in APPS_DATA_DIR