DiskUsage: ignore mountpoints with super long paths

So things like /var/snap/microk8s/common/run/containerd/ won't
spam and jeopardize the disk usage feature.

Usually they are very unlikely to be useful.
This commit is contained in:
Jesse Chan
2020-12-01 18:42:15 +08:00
parent 73c37b8240
commit b6ebee6351
+13 -7
View File
@@ -57,13 +57,19 @@ class DiskUsage extends (EventEmitter as new () => TypedEmitter<DiskUsageEvents>
if (!isPlatformSupported()) {
return Promise.reject();
}
return diskUsage[process.platform as SupportedPlatform]().then((disks) => {
if (disks.length !== this.disks.length || disks.some((d, i) => d.used !== this.disks[i].used)) {
this.tLastChange = Date.now();
this.disks = disks;
this.emit('DISK_USAGE_CHANGE', this.getDiskUsage());
}
});
return diskUsage[process.platform as SupportedPlatform]()
.then((disks) => {
// Mountpoints with a very long path are unlikely to be useful.
return disks.filter((disk) => disk.target.length < 30);
})
.then((disks) => {
if (disks.length !== this.disks.length || disks.some((d, i) => d.used !== this.disks[i].used)) {
this.tLastChange = Date.now();
this.disks = disks;
this.emit('DISK_USAGE_CHANGE', this.getDiskUsage());
}
});
};
getDiskUsage(): DiskUsageSummary {