du: better error handling of du

du can fail when files and directories go missing. luckily, when du fails,
it still provides the best effort output
This commit is contained in:
Girish Ramakrishnan
2024-11-06 14:53:41 +01:00
parent 9cf235af39
commit 6407d795ed
2 changed files with 7 additions and 4 deletions

View File

@@ -40,10 +40,10 @@ const assert = require('assert'),
safe = require('safetydance'),
shell = require('../shell.js')('filesystem');
// the du call in the function below requires root
async function getAvailableSize(apiConfig) {
assert.strictEqual(typeof apiConfig, 'object');
// note that df returns the disk size (as opposed to the apparent size)
const [error, dfResult] = await safe(df.file(apiConfig.rootPath));
if (error) throw new BoxError(BoxError.FS_ERROR, `Error when checking for disk space: ${error.message}`);