fsSize() added optional drive parameter

This commit is contained in:
Sebastian Hildebrandt
2023-06-06 13:28:50 +02:00
parent 1df611af74
commit 8c22e42bf3
7 changed files with 99 additions and 81 deletions
+15 -4
View File
@@ -36,7 +36,12 @@ let _disk_io = {};
// --------------------------
// FS - mounted file systems
function fsSize(callback) {
function fsSize(drive, callback) {
if (util.isFunction(drive)) {
callback = drive;
drive = '';
}
let macOsDisks = [];
let osMounts = [];
@@ -61,6 +66,7 @@ function fsSize(callback) {
function filterLines(stdout) {
let lines = stdout.toString().split('\n');
lines.shift();
if (stdout.toString().toLowerCase().indexOf('filesystem')) {
let removeLines = 0;
for (let i = 0; i < lines.length; i++) {
@@ -131,7 +137,7 @@ function fsSize(callback) {
}
}
if (_linux) {
cmd = 'df -lkPTx squashfs';
cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL';
execSync('cat /proc/mounts 2>/dev/null').toString().split('\n').filter(line => {
return line.startsWith('/');
}).forEach((line) => {
@@ -147,6 +153,11 @@ function fsSize(callback) {
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
let lines = filterLines(stdout);
data = parseDf(lines);
if (drive) {
data = data.filter(item => {
return item.fs.toLowerCase().indexOf(drive.toLowerCase()) >= 0 || item.mount.toLowerCase().indexOf(drive.toLowerCase()) >= 0;
});
}
if (!error || data.length) {
if (callback) {
callback(data);
@@ -172,8 +183,8 @@ function fsSize(callback) {
}
if (_windows) {
try {
// util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => {
util.powerShell('Get-CimInstance Win32_logicaldisk | select Access,Caption,FileSystem,FreeSpace,Size | fl').then((stdout, error) => {
const cmd = `Get-WmiObject Win32_logicaldisk | select Caption,FileSystem,FreeSpace,Size ${drive ? '| where -property Caption -eq ' + drive : ''} | fl`;
util.powerShell(cmd).then((stdout, error) => {
if (!error) {
let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) {
+1 -1
View File
@@ -967,7 +967,7 @@ export function memLayout(cb?: (data: Systeminformation.MemLayoutData[]) => any)
export function battery(cb?: (data: Systeminformation.BatteryData) => any): Promise<Systeminformation.BatteryData>;
export function graphics(cb?: (data: Systeminformation.GraphicsData) => any): Promise<Systeminformation.GraphicsData>;
export function fsSize(cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>;
export function fsSize(drive?: string, cb?: (data: Systeminformation.FsSizeData[]) => any): Promise<Systeminformation.FsSizeData[]>;
export function fsOpenFiles(cb?: (data: Systeminformation.FsOpenFilesData[]) => any): Promise<Systeminformation.FsOpenFilesData[]>;
export function blockDevices(cb?: (data: Systeminformation.BlockDevicesData[]) => any): Promise<Systeminformation.BlockDevicesData[]>;
export function fsStats(cb?: (data: Systeminformation.FsStatsData) => any): Promise<Systeminformation.FsStatsData>;