systeminformation 5.33.9 → 5.33.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/filesystem.js +87 -13
  2. package/package.json +1 -1
package/lib/filesystem.js CHANGED
@@ -43,8 +43,20 @@ function fsSize(drive, callback) {
43
43
  }
44
44
 
45
45
  let macOsDisks = [];
46
+ const macOsFsTypes = new Map();
46
47
  let osMounts = [];
47
48
 
49
+ // macOS df has no type column, so the type used to be guessed from diskutil - which only ever
50
+ // produced APFS, HFS or NFS and therefore never recognised zfs, exfat, msdos or smbfs. mount
51
+ // knows the real type, so prefer it and keep the old names for the three it could produce.
52
+ function macOsFsType(fs) {
53
+ const type = macOsFsTypes.get(fs);
54
+ if (!type) {
55
+ return getmacOsFsType(fs);
56
+ }
57
+ return type === 'apfs' ? 'APFS' : type === 'hfs' ? 'HFS' : type === 'nfs' ? 'NFS' : type;
58
+ }
59
+
48
60
  function getmacOsFsType(fs) {
49
61
  if (!fs.startsWith('/')) {
50
62
  return 'NFS';
@@ -86,6 +98,59 @@ function fsSize(drive, callback) {
86
98
  return lines;
87
99
  }
88
100
 
101
+ // ZFS datasets share the pool, so df only reports what a dataset references itself - a parent
102
+ // holding its data in child datasets looks empty (#1017). Only `zfs list` knows the
103
+ // hierarchical usage, so query it once when a zfs mount is present.
104
+ function applyZfsUsage(data, cb) {
105
+ if (!data.some((item) => item.type === 'zfs')) {
106
+ return cb(data);
107
+ }
108
+ exec('zfs list -H -p -o name,used,avail,mountpoint', { ...util.execOptsLinux, timeout: 5000 }, (error, stdout) => {
109
+ if (error) {
110
+ // a truncated or timed out listing would correct only part of the datasets and leave the
111
+ // rest on their df values - correct none instead, so the result stays consistent
112
+ return cb(data);
113
+ }
114
+ const byMount = Object.create(null);
115
+ const byName = Object.create(null);
116
+ (stdout || '')
117
+ .toString()
118
+ .split('\n')
119
+ .forEach((line) => {
120
+ const parts = line.split('\t');
121
+ if (parts.length < 4) {
122
+ return;
123
+ }
124
+ const entry = { used: parseInt(parts[1], 10), available: parseInt(parts[2], 10) };
125
+ if (isNaN(entry.used) || isNaN(entry.available)) {
126
+ return;
127
+ }
128
+ byName[parts[0]] = entry;
129
+ const mount = parts[3].trim();
130
+ // several datasets can carry the same mountpoint (root-on-zfs boot environments all
131
+ // declare "/"), so the mount index is only a fallback - keep the first one
132
+ if (mount.startsWith('/') && !byMount[mount]) {
133
+ byMount[mount] = entry;
134
+ }
135
+ });
136
+ data.forEach((item) => {
137
+ if (item.type !== 'zfs') {
138
+ return;
139
+ }
140
+ // the fs column is the exact dataset name and therefore unambiguous, unlike the mountpoint
141
+ const dataset = byName[item.fs] || byMount[item.mount];
142
+ if (!dataset || !(dataset.used + dataset.available)) {
143
+ return;
144
+ }
145
+ item.used = dataset.used;
146
+ item.available = dataset.available;
147
+ item.size = dataset.used + dataset.available;
148
+ item.use = parseFloat(((100.0 * dataset.used) / item.size).toFixed(2));
149
+ });
150
+ cb(data);
151
+ });
152
+ }
153
+
89
154
  function parseDf(lines) {
90
155
  const data = [];
91
156
  // filesystem (first column) and mount point (last column) may contain spaces:
@@ -98,7 +163,7 @@ function fsSize(drive, callback) {
98
163
  const parts = line.trim().match(hasType ? dfWithType : dfNoType);
99
164
  if (parts && (parts[1].startsWith('/') || parts[hasType ? 6 : 5] === '/' || parts[1].indexOf('/') > 0 || parts[1].indexOf(':') === 1 || (!_darwin && !isLinuxTmpFs(parts[2])))) {
100
165
  const fs = parts[1];
101
- const fsType = hasType ? parts[2] : getmacOsFsType(parts[1]);
166
+ const fsType = hasType ? parts[2] : macOsFsType(parts[1]);
102
167
  const size = parseInt(parts[hasType ? 3 : 2], 10) * 1024;
103
168
  const used = parseInt(parts[hasType ? 4 : 3], 10) * 1024;
104
169
  const available = parseInt(parts[hasType ? 5 : 4], 10) * 1024;
@@ -142,11 +207,16 @@ function fsSize(drive, callback) {
142
207
  execSync('mount')
143
208
  .toString()
144
209
  .split('\n')
145
- .filter((line) => {
146
- return line.startsWith('/');
147
- })
148
210
  .forEach((line) => {
149
- osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1;
211
+ // mount output: "<fs> on <mountpoint> (<type>, <options>)"
212
+ const fs = line.split(' ')[0];
213
+ const type = line.match(/\(([^),]+)[^)]*\)$/);
214
+ if (fs && type) {
215
+ macOsFsTypes.set(fs, type[1].trim().toLowerCase());
216
+ }
217
+ if (line.startsWith('/')) {
218
+ osMounts[fs] = line.toLowerCase().indexOf('read-only') === -1;
219
+ }
150
220
  });
151
221
  } catch {
152
222
  util.noop();
@@ -195,19 +265,23 @@ function fsSize(drive, callback) {
195
265
  });
196
266
  }
197
267
  if ((!error || data.length) && stdout.toString().trim() !== '') {
198
- if (callback) {
199
- callback(data);
200
- }
201
- resolve(data);
268
+ applyZfsUsage(data, (data) => {
269
+ if (callback) {
270
+ callback(data);
271
+ }
272
+ resolve(data);
273
+ });
202
274
  } else {
203
275
  exec('df -kPT 2>/dev/null', { maxBuffer: 1024 * 1024 }, (error, stdout) => {
204
276
  // fixed issue alpine fallback
205
277
  const lines = filterLines(stdout);
206
278
  data = parseDf(lines);
207
- if (callback) {
208
- callback(data);
209
- }
210
- resolve(data);
279
+ applyZfsUsage(data, (data) => {
280
+ if (callback) {
281
+ callback(data);
282
+ }
283
+ resolve(data);
284
+ });
211
285
  });
212
286
  }
213
287
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.33.9",
3
+ "version": "5.33.10",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",