Skip to content

Commit 80ee3fd

Browse files
committed
helpers.ts: improve compatibility with df output
- The df command can return a non-zero exit status but still contain enough info for us to parse local disk sizes.
1 parent 3bce66c commit 80ee3fd

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

RELEASES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ based on [Keep a Changelog].
55

66
## TopHat vNext - Unreleased
77

8+
- Fixed disk monitor problem with sshfs mounts
89
- Added German translation (from [theinfamousben](https://github.com/theinfamousben))
910

1011
## TopHat 21 - February 23, 2025

src/helpers.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,31 +140,37 @@ export async function readFileSystems(): Promise<FSUsage[]> {
140140
Gio.SubprocessFlags.STDOUT_PIPE
141141
);
142142
proc.communicate_utf8_async(null, null).then(([stdout]) => {
143-
const output = stdout as unknown as string;
144-
const lines = output.split('\n');
145-
for (const line of lines) {
146-
const m = line.match(RE_DF_IS_DISK);
147-
if (m) {
148-
const details = m[2].match(RE_DF_DISK_USAGE);
149-
if (details) {
150-
const dev = m[1];
151-
const cap = parseInt(details[1]) * 1024;
152-
const used = parseInt(details[2]) * 1024;
153-
const mount = details[5];
154-
let fileSystem = new FSUsage(dev, cap, used, mount);
155-
if (fileSystems.has(dev)) {
156-
const old = fileSystems.get(dev);
157-
if (old && old.mount.length < mount.length) {
158-
// Only report one mount per device; use the shortest file path
159-
fileSystem = old;
143+
// Try to process the output even if the exit status != 0
144+
if (stdout) {
145+
const output = stdout as unknown as string;
146+
const lines = output.split('\n');
147+
for (const line of lines) {
148+
const m = line.match(RE_DF_IS_DISK);
149+
if (m) {
150+
const details = m[2].match(RE_DF_DISK_USAGE);
151+
if (details) {
152+
const dev = m[1];
153+
const cap = parseInt(details[1]) * 1024;
154+
const used = parseInt(details[2]) * 1024;
155+
const mount = details[5];
156+
let fileSystem = new FSUsage(dev, cap, used, mount);
157+
if (fileSystems.has(dev)) {
158+
const old = fileSystems.get(dev);
159+
if (old && old.mount.length < mount.length) {
160+
// Only report one mount per device; use the shortest file path
161+
fileSystem = old;
162+
}
160163
}
164+
fileSystems.set(dev, fileSystem);
161165
}
162-
fileSystems.set(dev, fileSystem);
163166
}
164167
}
165-
166168
resolve(Array.from(fileSystems.values()));
167169
return;
170+
} else {
171+
console.warn('[TopHat] Could not run df -P: ');
172+
reject('Could not run df -P');
173+
return;
168174
}
169175
});
170176
} catch (e) {

0 commit comments

Comments
 (0)