For some reason using df with regular promises breaks and calls catch without error
This commit is contained in:
@@ -59,7 +59,7 @@ function getBackupPath(apiConfig) {
|
||||
}
|
||||
|
||||
// the du call in the function below requires root
|
||||
function checkPreconditions(apiConfig, dataLayout, callback) {
|
||||
async function checkPreconditions(apiConfig, dataLayout, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
@@ -74,21 +74,24 @@ function checkPreconditions(apiConfig, dataLayout, callback) {
|
||||
|
||||
debug(`checkPreconditions: ${used} bytes`);
|
||||
|
||||
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 || apiConfig.provider === PROVIDER_EXT4) {
|
||||
if (result.mountpoint !== apiConfig.mountPoint) return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.mountPoint} is not mounted`));
|
||||
} else if (apiConfig.provider === PROVIDER_MOUNTPOINT) {
|
||||
if (result.mountpoint === '/') return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.backupFolder} is not mounted`));
|
||||
}
|
||||
let result;
|
||||
try {
|
||||
result = await df.file(getBackupPath(apiConfig));
|
||||
} catch(error) {
|
||||
return callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
}
|
||||
|
||||
const needed = 0.6 * used + (1024 * 1024 * 1024); // check if there is atleast 1GB left afterwards. aim for 60% because rsync/tgz won't need full 100%
|
||||
if (result.available <= needed) return callback(new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${prettyBytes(needed)} Available: ${prettyBytes(result.available)}`));
|
||||
// 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 || apiConfig.provider === PROVIDER_EXT4) {
|
||||
if (result.mountpoint !== apiConfig.mountPoint) return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.mountPoint} is not mounted`));
|
||||
} else if (apiConfig.provider === PROVIDER_MOUNTPOINT) {
|
||||
if (result.mountpoint === '/') return callback(new BoxError(BoxError.FS_ERROR, `${apiConfig.backupFolder} is not mounted`));
|
||||
}
|
||||
|
||||
callback(null);
|
||||
}).catch(function (error) {
|
||||
callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
});
|
||||
const needed = 0.6 * used + (1024 * 1024 * 1024); // check if there is atleast 1GB left afterwards. aim for 60% because rsync/tgz won't need full 100%
|
||||
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);
|
||||
}
|
||||
|
||||
function hasChownSupportSync(apiConfig) {
|
||||
|
||||
Reference in New Issue
Block a user