system: filesystems in exclude are excluded from content analysis

some disks can be very slow and noisy (at home). this allows users to simply skip them.
also, applicable for large storage boxes
This commit is contained in:
Girish Ramakrishnan
2024-11-30 13:03:34 +01:00
parent 320ddfda2e
commit 2a6c52800b
6 changed files with 16 additions and 6 deletions
+6 -2
View File
@@ -217,7 +217,7 @@ async function getMemory() {
}
async function getDiskUsage() {
const cache = safe.JSON.parse(safe.fs.readFileSync(paths.DISK_USAGE_FILE, 'utf8'));
const cache = safe.JSON.parse(safe.fs.readFileSync(paths.DISK_USAGE_CACHE_FILE, 'utf8'));
if (cache?.disks) {
cache.filesystems = cache.disks; // legacy cache file had "disks"
delete cache.disks;
@@ -234,6 +234,7 @@ async function updateDiskUsage(progressCallback) {
let percent = 1;
const dockerDf = await docker.df();
const excludePaths = (safe.fs.readFileSync(paths.DISK_USAGE_EXCLUDE_FILE, 'utf8') || '').split('\n');
const fsCount = Object.keys(filesystems).length;
for (const fsPath in filesystems) {
@@ -256,6 +257,9 @@ async function updateDiskUsage(progressCallback) {
content.usage = dockerDf.LayersSize;
} else if (content.id === 'docker-volumes') {
content.usage = dockerDf.Volumes.map((v) => v.UsageData.Size).reduce((a,b) => a + b, 0);
} else if (excludePaths.includes(fsPath)) {
debug(`updateDiskUsage: skipping since path ${fsPath} is excluded`);
content.usage = 0;
} else {
const [error, usage] = await safe(du(content.path));
if (error) progressCallback({ message: `du error: ${error.message}`}); // can happen if app is installing etc
@@ -265,7 +269,7 @@ async function updateDiskUsage(progressCallback) {
}
}
if (!safe.fs.writeFileSync(paths.DISK_USAGE_FILE, JSON.stringify({ ts: now, filesystems }, null, 4), 'utf8')) throw new BoxError(BoxError.FS_ERROR, `Could not write du cache file: ${safe.error.message}`);
if (!safe.fs.writeFileSync(paths.DISK_USAGE_CACHE_FILE, JSON.stringify({ ts: now, filesystems }, null, 4), 'utf8')) throw new BoxError(BoxError.FS_ERROR, `Could not write du cache file: ${safe.error.message}`);
return filesystems;
}