rename to checkBackupPreconditions
since this is called only by the backup logic
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
exports = module.exports = {
|
||||
getRootPath,
|
||||
checkPreconditions,
|
||||
checkBackupPreconditions,
|
||||
|
||||
upload,
|
||||
download,
|
||||
@@ -73,7 +73,7 @@ function prettyBytes(bytes) {
|
||||
}
|
||||
|
||||
// the du call in the function below requires root
|
||||
async function checkPreconditions(apiConfig, dataLayout) {
|
||||
async function checkBackupPreconditions(apiConfig, dataLayout) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
|
||||
|
||||
@@ -89,13 +89,13 @@ async function checkPreconditions(apiConfig, dataLayout) {
|
||||
|
||||
let used = 0;
|
||||
for (const localPath of dataLayout.localPaths()) {
|
||||
debug(`checkPreconditions: getting disk usage of ${localPath}`);
|
||||
debug(`checkBackupPreconditions: getting disk usage of ${localPath}`);
|
||||
const result = safe.child_process.execSync(`du -Dsb ${localPath}`, { encoding: 'utf8' });
|
||||
if (!result) throw new BoxError(BoxError.FS_ERROR, `du error: ${safe.error.message}`);
|
||||
used += parseInt(result, 10);
|
||||
}
|
||||
|
||||
debug(`checkPreconditions: ${used} bytes`);
|
||||
debug(`checkBackupPreconditions: ${used} bytes`);
|
||||
|
||||
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 (rootPath.available <= needed) throw new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${prettyBytes(needed)} Available: ${prettyBytes(rootPath.available)}`);
|
||||
|
||||
Reference in New Issue
Block a user