|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const { stderr } = require('process'); |
4 | | - |
5 | 3 | const execFile = require('child_process').execFile, |
6 | 4 | log4js = require('log4js'), |
7 | 5 | host_platform = process.platform, |
@@ -659,11 +657,42 @@ class VboxGuestProperty { |
659 | 657 | enumerate(vmname, callback) { |
660 | 658 | this.vboxmanage( |
661 | 659 | ['guestproperty', 'enumerate', vmname], |
662 | | - (err, stdout, stderr) => { |
| 660 | + (err, stdout, _) => { |
| 661 | + if (err) { |
| 662 | + throw err; |
| 663 | + } |
663 | 664 | const arrOfProps = stdout.split('\n'); |
| 665 | + const nameRegex = /(?<=Name: ).+?(?=\,)/; |
| 666 | + const valueRegex = /(?<=value: ).+?(?=\,)/; |
| 667 | + const timestampRegex = /(?<=timestamp: ).+?(?=\,)/; |
| 668 | + const flagsRegex = /(?<=flags: ).*/; |
| 669 | + |
664 | 670 | const arrOfPropsParsed = []; |
665 | | - arrOfProps.forEach((prop) => {}); |
666 | | - callback(err, stdout, stderr); |
| 671 | + arrOfProps |
| 672 | + .filter((prop) => !!prop) |
| 673 | + .forEach((prop) => { |
| 674 | + const nameMatch = prop.match(nameRegex).shift(), |
| 675 | + value = prop.match(valueRegex).shift(), |
| 676 | + timestamp = prop.match(timestampRegex).shift(), |
| 677 | + flags = prop |
| 678 | + .match(flagsRegex) |
| 679 | + .shift() |
| 680 | + .split(',') |
| 681 | + .map((flag) => flag.replace(' ', '')), |
| 682 | + nameMatchSplit = nameMatch |
| 683 | + .split('/') |
| 684 | + .filter((name) => name !== ''), |
| 685 | + key = nameMatchSplit[2], |
| 686 | + namespace = nameMatchSplit[1]; |
| 687 | + arrOfPropsParsed.push({ |
| 688 | + key, |
| 689 | + value, |
| 690 | + namespace, |
| 691 | + timestamp, |
| 692 | + flags, |
| 693 | + }); |
| 694 | + }); |
| 695 | + callback(err, arrOfPropsParsed); |
667 | 696 | } |
668 | 697 | ); |
669 | 698 | } |
|
0 commit comments