diff --git a/src/sftp.js b/src/sftp.js index b102ae665..d0b0409da 100644 --- a/src/sftp.js +++ b/src/sftp.js @@ -30,46 +30,43 @@ async function rebuild(serviceConfig, options) { const memory = system.getMemoryAllocation(memoryLimit); const cloudronToken = hat(8 * 128); - let dataDirs = []; - const stat = safe.fs.lstatSync(paths.APPS_DATA_DIR); if (!stat) throw new BoxError(BoxError.FS_ERROR, safe.error); const resolvedAppDataDir = stat.isSymbolicLink() ? safe.fs.readlinkSync(paths.APPS_DATA_DIR) : paths.APPS_DATA_DIR; - dataDirs.push({ hostDir: resolvedAppDataDir, mountDir: '/mnt/appsdata' }); + const dataDirs = [{ hostDir: resolvedAppDataDir, mountDir: '/mnt/appsdata' }]; - const result = await apps.list(); - - result.forEach(function (app) { - if (!app.manifest.addons['localstorage'] || !app.dataDir) return; + // custom app data directories + const allApps = await apps.list(); + for (const app of allApps) { + if (!app.manifest.addons['localstorage'] || !app.dataDir) continue; const hostDir = apps.getDataDir(app, app.dataDir), mountDir = `/mnt/${app.id}`; if (!safe.fs.existsSync(hostDir)) { // this can fail if external mount does not have permissions for yellowtent user // do not create host path when cloudron is restoring. this will then create dir with root perms making restore logic fail debug(`Ignoring app data dir ${hostDir} for ${app.id} since it does not exist`); - return; + continue; } dataDirs.push({ hostDir, mountDir }); - }); - - let allVolumes = await volumes.list(); + } + // volume directories dataDirs.push({ hostDir: '/mnt/volumes', mountDir: '/mnt/volumes' }); - - allVolumes.forEach(function (volume) { - if (volume.hostPath.startsWith('/mnt/volumes/')) return; + const allVolumes = await volumes.list(); + for (const volume of allVolumes) { + if (volume.hostPath.startsWith('/mnt/volumes/')) continue; if (!safe.fs.existsSync(volume.hostPath)) { debug(`Ignoring volume host path ${volume.hostPath} since it does not exist`); - return; + continue; } dataDirs.push({ hostDir: volume.hostPath, mountDir: `/mnt/${volume.id}` }); - }); + } - const mounts = dataDirs.map(function (v) { return `-v "${v.hostDir}:${v.mountDir}"`; }).join(' '); + const mounts = dataDirs.map(v => `-v "${v.hostDir}:${v.mountDir}"`).join(' '); const cmd = `docker run --restart=always -d --name="sftp" \ --hostname sftp \ --net cloudron \