refactor: move moveDataDir into services
This commit is contained in:
@@ -38,8 +38,7 @@ const apps = require('./apps.js'),
|
||||
shell = require('./shell.js')('apptask'),
|
||||
_ = require('./underscore.js');
|
||||
|
||||
const MV_VOLUME_CMD = path.join(__dirname, 'scripts/mvvolume.sh'),
|
||||
LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }),
|
||||
const LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }),
|
||||
CONFIGURE_LOGROTATE_CMD = path.join(__dirname, 'scripts/configurelogrotate.sh');
|
||||
|
||||
function makeTaskError(error, app) {
|
||||
@@ -209,25 +208,6 @@ async function downloadIcon(app) {
|
||||
await updateApp(app, { appStoreIcon });
|
||||
}
|
||||
|
||||
async function moveDataDir(app, targetVolumeId, targetVolumePrefix) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.ok(app.manifest.addons.localstorage, 'should have local storage addon');
|
||||
assert(targetVolumeId === null || typeof targetVolumeId === 'string');
|
||||
assert(targetVolumePrefix === null || typeof targetVolumePrefix === 'string');
|
||||
|
||||
const resolvedSourceDir = await apps.getStorageDir(app);
|
||||
const resolvedTargetDir = await apps.getStorageDir(Object.assign({}, app, { storageVolumeId: targetVolumeId, storageVolumePrefix: targetVolumePrefix }));
|
||||
|
||||
debug(`moveDataDir: migrating data from ${resolvedSourceDir} to ${resolvedTargetDir}`);
|
||||
|
||||
if (resolvedSourceDir !== resolvedTargetDir) {
|
||||
const [error] = await safe(shell.promises.sudo([ MV_VOLUME_CMD, resolvedSourceDir, resolvedTargetDir ], {}));
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Error migrating data directory: ${error.message}`);
|
||||
}
|
||||
|
||||
await updateApp(app, { storageVolumeId: targetVolumeId, storageVolumePrefix: targetVolumePrefix });
|
||||
}
|
||||
|
||||
async function downloadImage(manifest) {
|
||||
assert.strictEqual(typeof manifest, 'object');
|
||||
|
||||
@@ -531,13 +511,10 @@ async function migrateDataDirCommand(app, args, progressCallback) {
|
||||
await progressCallback({ percent: 10, message: 'Deleting old containers' });
|
||||
await deleteContainers(app, { managedOnly: true });
|
||||
|
||||
// re-setup addon since this creates the localStorage destination
|
||||
await progressCallback({ percent: 50, message: 'Setting up addons' });
|
||||
await services.setupAddons(Object.assign({}, app, { storageVolumeId: newStorageVolumeId, storageVolumePrefix: newStorageVolumePrefix }), _.pick(app.manifest.addons, 'localstorage'));
|
||||
|
||||
if (app.manifest.addons?.localstorage) {
|
||||
await progressCallback({ percent: 60, message: 'Moving data dir' });
|
||||
await moveDataDir(app, newStorageVolumeId, newStorageVolumePrefix);
|
||||
await progressCallback({ percent: 40, message: 'Moving data dir' });
|
||||
await services.moveDataDir(app, newStorageVolumeId, newStorageVolumePrefix);
|
||||
await updateApp(app, { storageVolumeId: newStorageVolumeId, storageVolumePrefix: newStorageVolumePrefix });
|
||||
}
|
||||
|
||||
await progressCallback({ percent: 90, message: 'Creating container' });
|
||||
|
||||
Reference in New Issue
Block a user