du: do not crash when app dir is missing

this can happen when the app is installing/uninstalling
This commit is contained in:
Girish Ramakrishnan
2022-10-13 23:34:47 +02:00
parent 91d1d0b74b
commit eb5c90a2e7

View File

@@ -12,7 +12,6 @@ exports = module.exports = {
const apps = require('./apps.js'),
assert = require('assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
debug = require('debug')('box:disks'),
df = require('@sindresorhus/df'),
docker = require('./docker.js'),
@@ -88,7 +87,7 @@ async function getDisks() {
}
for (const app of await apps.list()) {
if (app.manifest.id === constants.PROXY_APP_APPSTORE_ID) continue;
if (!app.manifest.addons?.localstorage) continue;
const dataDir = await apps.getStorageDir(app);
const [, dfResult] = await safe(df.file(dataDir));
@@ -170,7 +169,9 @@ async function updateDiskUsage(progressCallback) {
if (content.id === 'docker') {
content.usage = (await docker.df()).LayersSize;
} else {
content.usage = await du(content.path);
const [error, usage] = await safe(du(content.path));
if (error) progressCallback({ message: `du error: ${error.message}`}); // can happen if app is installing etc
content.usage = usage || 0;
}
progressCallback({ message: `du of ${JSON.stringify(content)}: ${content.usage}`});
}