@@ -17,8 +17,7 @@ const util = require('./util');
17
17
const fs = require ( 'fs' ) ;
18
18
19
19
const exec = require ( 'child_process' ) . exec ;
20
- const execSync = require ( 'child_process' ) . execSync ;
21
- const execPromiseSave = util . promisifySave ( require ( 'child_process' ) . exec ) ;
20
+ const execAsync = util . execAsync ;
22
21
23
22
let _platform = process . platform ;
24
23
@@ -115,7 +114,7 @@ function fsSize(drive, callback) {
115
114
}
116
115
117
116
return new Promise ( ( resolve ) => {
118
- process . nextTick ( ( ) => {
117
+ process . nextTick ( async ( ) => {
119
118
let data = [ ] ;
120
119
if ( _linux || _freebsd || _openbsd || _netbsd || _darwin ) {
121
120
let cmd = '' ;
@@ -124,10 +123,10 @@ function fsSize(drive, callback) {
124
123
if ( _darwin ) {
125
124
cmd = 'df -kP' ;
126
125
try {
127
- macOsDisks = execSync ( 'diskutil list' ) . toString ( ) . split ( '\n' ) . filter ( line => {
126
+ macOsDisks = ( await execAsync ( 'diskutil list' ) ) . toString ( ) . split ( '\n' ) . filter ( line => {
128
127
return ! line . startsWith ( '/' ) && line . indexOf ( ':' ) > 0 ;
129
128
} ) ;
130
- execSync ( 'mount' ) . toString ( ) . split ( '\n' ) . filter ( line => {
129
+ ( await execAsync ( 'mount' ) ) . toString ( ) . split ( '\n' ) . filter ( line => {
131
130
return line . startsWith ( '/' ) ;
132
131
} ) . forEach ( ( line ) => {
133
132
osMounts [ line . split ( ' ' ) [ 0 ] ] = line . toLowerCase ( ) . indexOf ( 'read-only' ) === - 1 ;
@@ -139,7 +138,7 @@ function fsSize(drive, callback) {
139
138
if ( _linux ) {
140
139
try {
141
140
cmd = 'export LC_ALL=C; df -lkPTx squashfs; unset LC_ALL' ;
142
- execSync ( 'cat /proc/mounts 2>/dev/null' , util . execOptsLinux ) . toString ( ) . split ( '\n' ) . filter ( line => {
141
+ ( await execAsync ( 'cat /proc/mounts 2>/dev/null' , util . execOptsLinux ) ) . toString ( ) . split ( '\n' ) . filter ( line => {
143
142
return line . startsWith ( '/' ) ;
144
143
} ) . forEach ( ( line ) => {
145
144
osMounts [ line . split ( ' ' ) [ 0 ] ] = osMounts [ line . split ( ' ' ) [ 0 ] ] || false ;
@@ -154,7 +153,7 @@ function fsSize(drive, callback) {
154
153
if ( _freebsd || _openbsd || _netbsd ) {
155
154
try {
156
155
cmd = 'df -lkPT' ;
157
- execSync ( 'mount' ) . toString ( ) . split ( '\n' ) . forEach ( ( line ) => {
156
+ ( await execAsync ( 'mount' ) ) . toString ( ) . split ( '\n' ) . forEach ( ( line ) => {
158
157
osMounts [ line . split ( ' ' ) [ 0 ] ] = line . toLowerCase ( ) . indexOf ( 'read-only' ) === - 1 ;
159
158
} ) ;
160
159
} catch ( e ) {
@@ -420,13 +419,13 @@ function decodeMdabmData(lines) {
420
419
} ;
421
420
}
422
421
423
- function raidMatchLinux ( data ) {
422
+ async function raidMatchLinux ( data ) {
424
423
// for all block devices of type "raid%"
425
424
let result = data ;
426
425
try {
427
- data . forEach ( element => {
426
+ for ( let element of data ) {
428
427
if ( element . type . startsWith ( 'raid' ) ) {
429
- const lines = execSync ( `mdadm --export --detail /dev/${ element . name } ` , util . execOptsLinux ) . toString ( ) . split ( '\n' ) ;
428
+ const lines = ( await execAsync ( `mdadm --export --detail /dev/${ element . name } ` , util . execOptsLinux ) ) . toString ( ) . split ( '\n' ) ;
430
429
const mdData = decodeMdabmData ( lines ) ;
431
430
432
431
element . label = mdData . label ; // <- assign label info
@@ -441,7 +440,7 @@ function raidMatchLinux(data) {
441
440
} ) ;
442
441
}
443
442
}
444
- } ) ;
443
+ }
445
444
} catch ( e ) {
446
445
util . noop ( ) ;
447
446
}
@@ -570,27 +569,27 @@ function blkStdoutToObject(stdout) {
570
569
function blockDevices ( callback ) {
571
570
572
571
return new Promise ( ( resolve ) => {
573
- process . nextTick ( ( ) => {
572
+ process . nextTick ( async ( ) => {
574
573
let data = [ ] ;
575
574
if ( _linux ) {
576
575
// see https://wiki.ubuntuusers.de/lsblk/
577
576
// exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
578
- exec ( 'lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null' , { maxBuffer : 1024 * 1024 } , function ( error , stdout ) {
577
+ exec ( 'lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,TRAN,SERIAL,LABEL,MODEL,OWNER 2>/dev/null' , { maxBuffer : 1024 * 1024 } , async function ( error , stdout ) {
579
578
if ( ! error ) {
580
579
let lines = blkStdoutToObject ( stdout ) . split ( '\n' ) ;
581
580
data = parseBlk ( lines ) ;
582
- data = raidMatchLinux ( data ) ;
581
+ data = await raidMatchLinux ( data ) ;
583
582
data = matchDevicesLinux ( data ) ;
584
583
if ( callback ) {
585
584
callback ( data ) ;
586
585
}
587
586
resolve ( data ) ;
588
587
} else {
589
- exec ( 'lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null' , { maxBuffer : 1024 * 1024 } , function ( error , stdout ) {
588
+ exec ( 'lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER 2>/dev/null' , { maxBuffer : 1024 * 1024 } , async function ( error , stdout ) {
590
589
if ( ! error ) {
591
590
let lines = blkStdoutToObject ( stdout ) . split ( '\n' ) ;
592
591
data = parseBlk ( lines ) ;
593
- data = raidMatchLinux ( data ) ;
592
+ data = await raidMatchLinux ( data ) ;
594
593
}
595
594
if ( callback ) {
596
595
callback ( data ) ;
@@ -1056,7 +1055,7 @@ function diskLayout(callback) {
1056
1055
}
1057
1056
1058
1057
return new Promise ( ( resolve ) => {
1059
- process . nextTick ( ( ) => {
1058
+ process . nextTick ( async ( ) => {
1060
1059
1061
1060
const commitResult = res => {
1062
1061
for ( let i = 0 ; i < res . length ; i ++ ) {
@@ -1074,7 +1073,7 @@ function diskLayout(callback) {
1074
1073
if ( _linux ) {
1075
1074
let cmdFullSmart = '' ;
1076
1075
1077
- exec ( 'export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL' , { maxBuffer : 1024 * 1024 } , function ( error , stdout ) {
1076
+ exec ( 'export LC_ALL=C; lsblk -ablJO 2>/dev/null; unset LC_ALL' , { maxBuffer : 1024 * 1024 } , async function ( error , stdout ) {
1078
1077
if ( ! error ) {
1079
1078
try {
1080
1079
const out = stdout . toString ( ) . trim ( ) ;
@@ -1087,20 +1086,20 @@ function diskLayout(callback) {
1087
1086
} catch ( e ) {
1088
1087
// fallback to older version of lsblk
1089
1088
try {
1090
- const out2 = execSync ( 'export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL' , util . execOptsLinux ) . toString ( ) ;
1089
+ const out2 = ( await execAsync ( 'export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL' , util . execOptsLinux ) ) . toString ( ) ;
1091
1090
let lines = blkStdoutToObject ( out2 ) . split ( '\n' ) ;
1092
1091
const data = parseBlk ( lines ) ;
1093
1092
devices = data . filter ( item => { return ( item . type === 'disk' ) && item . size > 0 && ( ( item . model !== null && item . model !== '' ) || ( item . mount === '' && item . label === '' && item . fsType === '' ) ) ; } ) ;
1094
1093
} catch ( e ) {
1095
1094
util . noop ( ) ;
1096
1095
}
1097
1096
}
1098
- devices . forEach ( ( device ) => {
1097
+ for ( let device of devices ) {
1099
1098
let mediumType = '' ;
1100
1099
const BSDName = '/dev/' + device . name ;
1101
1100
const logical = device . name ;
1102
1101
try {
1103
- mediumType = execSync ( 'cat /sys/block/' + logical + '/queue/rotational 2>/dev/null' , util . execOptsLinux ) . toString ( ) . split ( '\n' ) [ 0 ] ;
1102
+ mediumType = ( await execAsync ( 'cat /sys/block/' + logical + '/queue/rotational 2>/dev/null' , util . execOptsLinux ) ) . toString ( ) . split ( '\n' ) [ 0 ] ;
1104
1103
} catch ( e ) {
1105
1104
util . noop ( ) ;
1106
1105
}
@@ -1131,7 +1130,7 @@ function diskLayout(callback) {
1131
1130
} ) ;
1132
1131
cmd += `printf "\n${ BSDName } |"; smartctl -H ${ BSDName } | grep overall;` ;
1133
1132
cmdFullSmart += `${ cmdFullSmart ? 'printf ",";' : '' } smartctl -a -j ${ BSDName } ;` ;
1134
- } ) ;
1133
+ }
1135
1134
} catch ( e ) {
1136
1135
util . noop ( ) ;
1137
1136
}
@@ -1406,10 +1405,10 @@ function diskLayout(callback) {
1406
1405
workload . push ( util . powerShell ( 'Get-PhysicalDisk | select BusType,MediaType,FriendlyName,Model,SerialNumber,Size | fl' ) ) ;
1407
1406
if ( util . smartMonToolsInstalled ( ) ) {
1408
1407
try {
1409
- const smartDev = JSON . parse ( execSync ( 'smartctl --scan -j' ) . toString ( ) ) ;
1408
+ const smartDev = JSON . parse ( ( await execAsync ( 'smartctl --scan -j' ) ) . toString ( ) ) ;
1410
1409
if ( smartDev && smartDev . devices && smartDev . devices . length > 0 ) {
1411
1410
smartDev . devices . forEach ( ( dev ) => {
1412
- workload . push ( execPromiseSave ( `smartctl -j -a ${ dev . name } ` , util . execOptsWin ) ) ;
1411
+ workload . push ( execAsync ( `smartctl -j -a ${ dev . name } ` , util . execOptsWin ) . catch ( ( ) => '' ) ) ;
1413
1412
} ) ;
1414
1413
}
1415
1414
} catch ( e ) {
0 commit comments