diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 891ee977d..4f4592f46 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -54,13 +54,6 @@ function checkPreconditions(apiConfig, dataLayout, callback) { assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout'); assert.strictEqual(typeof callback, 'function'); - // Check filesystem is mounted so we don't write into the actual folder on disk - if (apiConfig.provider === PROVIDER_SSHFS || apiConfig.provider === PROVIDER_CIFS || apiConfig.provider === PROVIDER_NFS) { - const mounts = safe.fs.readFileSync('/proc/mounts', 'utf8'); - const mountInfo = mounts.split('\n').filter(function (l) { return l.indexOf(apiConfig.mountPoint) !== -1; })[0]; - if (!mountInfo) return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.mountPoint} is not mounted`)); - } - let used = 0; for (let localPath of dataLayout.localPaths()) { debug(`checkPreconditions: getting disk usage of ${localPath}`); @@ -71,9 +64,17 @@ function checkPreconditions(apiConfig, dataLayout, callback) { debug(`checkPreconditions: ${used} bytes`); - df.file(getBackupPath(apiConfig)).then(function (diskUsage) { + df.file(getBackupPath(apiConfig)).then(function (result) { + + // Check filesystem is mounted so we don't write into the actual folder on disk + if (apiConfig.provider === PROVIDER_SSHFS || apiConfig.provider === PROVIDER_CIFS || apiConfig.provider === PROVIDER_NFS) { + if (result.mountpoint !== apiConfig.mountPoint) return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.mountPoint} is not mounted`)); + } else if (apiConfig.provider === PROVIDER_FILESYSTEM && apiConfig.externalDisk) { + if (result.mountpoint === '/') return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.backupFolder} is not mounted`)); + } + const needed = used + (1024 * 1024 * 1024); // check if there is atleast 1GB left afterwards - if (diskUsage.available <= needed) return callback(new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${prettyBytes(needed)} Available: ${prettyBytes(diskUsage.available)}`)); + if (result.available <= needed) return callback(new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${prettyBytes(needed)} Available: ${prettyBytes(result.available)}`)); callback(null); }).catch(function (error) { @@ -239,7 +240,7 @@ function testConfig(apiConfig, callback) { const mounts = safe.fs.readFileSync('/proc/mounts', 'utf8'); const mountInfo = mounts.split('\n').filter(function (l) { return l.indexOf(apiConfig.mountPoint) !== -1; })[0]; - if (!mountInfo) return callback(new BoxError(BoxError.BAD_FIELD, 'mountPoint is not mounted', { field: 'mountPoint' })); + if (!mountInfo) return callback(new BoxError(BoxError.BAD_FIELD, `${apiConfig.mountPoint} is not mounted`, { field: 'mountPoint' })); if (apiConfig.provider === PROVIDER_SSHFS && !mountInfo.split(' ').find(i => i === 'fuse.sshfs')) return callback(new BoxError(BoxError.BAD_FIELD, 'mountPoint must be a "fuse.sshfs" filesystem', { field: 'mountPoint' })); if (apiConfig.provider === PROVIDER_CIFS && !mountInfo.split(' ').find(i => i === 'cifs')) return callback(new BoxError(BoxError.BAD_FIELD, 'mountPoint must be a "cifs" filesystem', { field: 'mountPoint' }));