From 657e159cca98fb86cb8c38388afb4b9688a2c55a Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 8 Nov 2020 09:19:57 +0100 Subject: [PATCH] fsSize() correct fs type detection macOS (HFS, APFS, NFS) --- CHANGELOG.md | 1 + README.md | 4 ++-- docs/history.html | 5 +++++ docs/index.html | 4 ++-- lib/filesystem.js | 20 ++++++++++++++++++-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1bc15c..a3853de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.29.0 | 2020-11-08 | `fsSize()` correct fs type detection macOS (HFS, APFS, NFS) | | 4.28.1 | 2020-11-05 | code cleanup, removing debug console.log() | | 4.28.0 | 2020-11-04 | `graphics()` added deviceName (windows) | | 4.27.11 | 2020-10-26 | `inetChecksite()` fixed vulnerability: command injection | diff --git a/README.md b/README.md index 18abdb2..d0f8f0b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ [![Sponsoring][sponsor-badge]][sponsor-url] [![MIT license][license-img]][license-url] -This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 300 versions published, up to 2 mio downloads per month, > 18 mio downloads overall. Thank you to all who contributed to this project! +This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 300 versions published, up to 2 mio downloads per month, > 20 mio downloads overall. Thank you to all who contributed to this project! ## New Version 4.0 @@ -87,13 +87,13 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.29.0: `fsSize()` correct fs type detection macOS (HFS, APFS, NFS) - Version 4.28.0: `graphics()` added deviceName (Windows) - Version 4.27.0: `observe()` added observe / watch function - Version 4.26.0: `diskLayout()` added full S.M.A.R.T data (Linux) - Version 4.25.0: `get()` added function to get partial system info - Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6 - Version 4.23.0: `versions()` added param to specify which program/lib versions to detect -- Version 4.22.0: `services()` added pids (windows) - ... You can find all changes here: [detailed changelog][changelog-url] diff --git a/docs/history.html b/docs/history.html index 663040a..a9db895 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.29.0 + 2020-11-08 + fsSize() correct fs type detection macOS (HFS, APFS, NFS) + 4.28.1 2020-11-05 diff --git a/docs/index.html b/docs/index.html index c2af33a..293c193 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.28.1
+
Current Version: 4.29.0
@@ -207,7 +207,7 @@
Downloads last month
-
356
+
359
Dependends
diff --git a/lib/filesystem.js b/lib/filesystem.js index ed2ed10..bd62582 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -38,6 +38,17 @@ let _disk_io = {}; function fsSize(callback) { + let macOsDisks = []; + + function getmacOsFsType(fs) { + if (!fs.startsWith('/')) { return 'NFS' }; + const parts = fs.split('/'); + const fsShort = parts[parts.length - 1]; + const macOsDisksSingle = macOsDisks.filter(item => item.indexOf(fsShort) >= 0) + if (macOsDisksSingle.length === 1 && macOsDisksSingle[0].indexOf('APFS') >= 0) { return 'APFS' } + return 'HFS'; + } + function parseDf(lines) { let data = []; lines.forEach(function (line) { @@ -45,7 +56,7 @@ function fsSize(callback) { line = line.replace(/ +/g, ' ').split(' '); if (line && ((line[0].startsWith('/')) || (line[6] && line[6] === '/') || (line[0].indexOf('/') > 0))) { const fs = line[0]; - const fstype = ((_linux || _freebsd || _openbsd || _netbsd) ? line[1] : (line[0].startsWith('/')) ? 'HFS' : 'NFS'); + const fstype = ((_linux || _freebsd || _openbsd || _netbsd) ? line[1] : getmacOsFsType(line[0])); const size = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])) * 1024; const used = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2])) * 1024; const use = parseFloat((100.0 * ((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2]) / ((_linux || _freebsd || _openbsd || _netbsd) ? line[2] : line[1])).toFixed(2)); @@ -71,7 +82,12 @@ function fsSize(callback) { let data = []; if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { let cmd = ''; - if (_darwin) cmd = 'df -kP'; + if (_darwin) { + cmd = 'df -kP'; + macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => { + return !line.startsWith('/') && line.indexOf(':') > 0 + }); + } if (_linux) cmd = 'df -lkPTx squashfs | grep ^/'; if (_freebsd || _openbsd || _netbsd) cmd = 'df -lkPT'; exec(cmd, function (error, stdout) {