apptask: only move app uses localstorage addon

This commit is contained in:
Girish Ramakrishnan
2024-06-06 15:22:33 +02:00
parent 3b26f6f5ea
commit f386c326e2
6 changed files with 21 additions and 12 deletions
+4
View File
@@ -510,6 +510,8 @@ async function checkStorage(app, volumeId, prefix) {
if (prefix !== '' && path.normalize(prefix) !== prefix) throw new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" is not a normalized path`);
const sourceDir = await getStorageDir(app);
if (sourceDir === null) throw new BoxError(BoxError.BAD_STATE, 'App does not use localstorage addon');
const targetDir = path.join(volume.hostPath, prefix);
const rel = path.relative(sourceDir, targetDir);
if (!rel.startsWith('../') && rel.split('/').length > 1) throw new BoxError(BoxError.BAD_FIELD, 'Only one level subdirectory moves are supported');
@@ -557,6 +559,8 @@ function getDuplicateErrorDetails(errorMessage, locations, portBindings) {
async function getStorageDir(app) {
assert.strictEqual(typeof app, 'object');
if (!app.manifest.addons?.localstorage) return null;
if (!app.storageVolumeId) return path.join(paths.APPS_DATA_DIR, app.id, 'data');
const volume = await volumes.get(app.storageVolumeId);
if (!volume) throw new BoxError(BoxError.NOT_FOUND, 'Volume not found'); // not possible