refactor: move moveDataDir into services
This commit is contained in:
@@ -16,6 +16,8 @@ exports = module.exports = {
|
||||
|
||||
startServices,
|
||||
|
||||
moveDataDir, // localstorage specific command
|
||||
|
||||
setupAddons,
|
||||
teardownAddons,
|
||||
backupAddons,
|
||||
@@ -76,6 +78,7 @@ const RESTART_SERVICE_CMD = path.join(__dirname, 'scripts/restartservice.sh');
|
||||
const CLEARVOLUME_CMD = path.join(__dirname, 'scripts/clearvolume.sh');
|
||||
const RMVOLUME_CMD = path.join(__dirname, 'scripts/rmvolume.sh');
|
||||
const SETUPVOLUME_CMD = path.join(__dirname, 'scripts/setupvolume.sh');
|
||||
const MV_VOLUME_CMD = path.join(__dirname, 'scripts/mvvolume.sh');
|
||||
|
||||
// setup can be called multiple times for the same app (configure crash restart) and existing data must not be lost
|
||||
// teardown is destructive. app data stored with the addon is lost
|
||||
@@ -2207,3 +2210,20 @@ async function checkAddonsSupport(addons) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user