22
33// @todo use a promise library instead of so many callbacks
44
5- var execFile = require ( 'child_process' ) . execFile ,
5+ const execFile = require ( 'child_process' ) . execFile ,
66 host_platform = process . platform ,
77 logging = require ( './logging' ) ,
8- vBoxManageBinary ,
9- vbox_version ,
10- known_OS_types = {
8+ known_OS_types = {
119 WINDOWS : 'windows' ,
1210 MAC : 'mac' ,
1311 LINUX : 'linux'
14- } ,
15- allowedBinaries = [ "VBoxControl" , vBoxManageBinary ] ;
16-
12+ } ;
1713
14+ let vBoxManageBinary ,
15+ vbox_version ;
16+
1817
1918// Host operating system
2019if ( / ^ w i n / . test ( host_platform ) ) {
@@ -35,6 +34,10 @@ if (/^win/.test(host_platform)) {
3534
3635}
3736
37+ const
38+ allowedBinaries = [ "VBoxControl" , vBoxManageBinary ] ;
39+
40+
3841execFile ( vBoxManageBinary , [ "--version" ] , function ( error , stdout , stderr ) {
3942 // e.g., "4.3.38r106717" or "5.0.20r106931"
4043 vbox_version = stdout . split ( "." ) [ 0 ] ;
@@ -429,7 +432,7 @@ var guestproperty = {
429432 // The ostype is matched against the ID attribute of 'vboxmanage list ostypes'
430433 if ( stdout . indexOf ( 'ostype="Windows' ) !== - 1 ) {
431434 guestproperty . os_type = known_OS_types . WINDOWS ;
432- } else if ( stdout . indexOf ( 'ostype="MacOS' ) !== - 1 ) {
435+ } else if ( [ 'ostype="MacOS' , 'ostype="Mac OS machine' ] . includes ( stdout ) ) {
433436 guestproperty . os_type = known_OS_types . MAC ;
434437 } else {
435438 guestproperty . os_type = known_OS_types . LINUX ;
@@ -443,8 +446,9 @@ var guestproperty = {
443446 }
444447
445448 try {
446- vboxmanage ( 'showvminfo' , '--machinereadable' , vmname , getOSTypeCallback ) ;
449+ vboxmanage ( [ 'showvminfo' , '--machinereadable' , vmname ] , getOSTypeCallback ) ;
447450 } catch ( e ) {
451+ logging . error ( e ) ;
448452 logging . info ( 'Could not showvminfo for %s' , vmname ) ;
449453 }
450454 }
0 commit comments