diff --git a/src/backuptask.js b/src/backuptask.js index f4d974061..4aed92807 100644 --- a/src/backuptask.js +++ b/src/backuptask.js @@ -47,16 +47,6 @@ function canBackupApp(app) { app.installationState === apps.ISTATE_PENDING_UPDATE; // called from apptask } -// binary units (non SI) 1024 based -function prettyBytes(bytes) { - assert.strictEqual(typeof bytes, 'number'); - - const i = Math.floor(Math.log(bytes) / Math.log(1024)), - sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - - return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + '' + sizes[i]; -} - async function checkPreconditions(backupConfig, dataLayout) { assert.strictEqual(typeof backupConfig, 'object'); assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout'); @@ -79,7 +69,7 @@ async function checkPreconditions(backupConfig, dataLayout) { debug(`checkPreconditions: total required =${used} available=${df.available}`); 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 (df.available <= needed) throw new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${prettyBytes(needed)} Available: ${prettyBytes(df.available)}`); + if (df.available <= needed) throw new BoxError(BoxError.FS_ERROR, `Not enough disk space for backup. Needed: ${df.prettyBytes(needed)} Available: ${df.prettyBytes(df.available)}`); } // this function is called via backupupload (since it needs root to traverse app's directory) diff --git a/src/df.js b/src/df.js index 4c4228d78..0e19ea8be 100644 --- a/src/df.js +++ b/src/df.js @@ -2,13 +2,24 @@ exports = module.exports = { disks, - file + file, + prettyBytes }; const assert = require('assert'), BoxError = require('./boxerror.js'), safe = require('safetydance'); +// binary units (non SI) 1024 based +function prettyBytes(bytes) { + assert.strictEqual(typeof bytes, 'number'); + + const i = Math.floor(Math.log(bytes) / Math.log(1024)), + sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + '' + sizes[i]; +} + function parseLine(line) { const parts = line.split(/\s+/, 7); // this way the mountpoint can have spaces in it diff --git a/src/updater.js b/src/updater.js index 8904fa300..95a244f1a 100644 --- a/src/updater.js +++ b/src/updater.js @@ -127,7 +127,7 @@ async function checkFreeDiskSpace(neededSpace) { const [error, diskUsage] = await safe(df.file('/')); if (error) throw new BoxError(BoxError.FS_ERROR, error); - if (diskUsage.available < neededSpace) throw new BoxError(BoxError.FS_ERROR, 'Not enough disk space'); + if (diskUsage.available < neededSpace) throw new BoxError(BoxError.FS_ERROR, `Not enough disk space. Updates require at least 2GB of free space. Available: ${df.prettyBytes(diskUsage.available)}`); } async function update(boxUpdateInfo, options, progressCallback) {