Added basic checking of .conf files in working directory re #6. Simple check that file contains 'guest_os' (#7)

Thank you !
This commit is contained in:
Ben Hall 2021-11-07 16:57:19 +00:00 committed by GitHub
parent a9ae0e28fd
commit d38146736c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -52,7 +52,7 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
List<String> lines = File(name + '/' + name + '.ports').readAsLinesSync();
for (var line in lines) {
List<String> parts = line.split(',');
switch(parts[0]) {
switch (parts[0]) {
case 'ssh':
info.sshPort = parts[1];
break;
@ -64,12 +64,23 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
return info;
}
bool _isValidConf(conf) {
List<String> lines = File(conf).readAsLinesSync();
for (var line in lines) {
List<String> parts = line.split('=');
if (parts[0] == 'guest_os') {
return true;
}
}
return false;
}
void _getVms(context) async {
List<String> currentVms = [];
Map<String, VmInfo> activeVms = {};
await for (var entity in Directory.current.list(recursive: false, followLinks: true)) {
if (entity.path.endsWith('.conf')) {
if ((entity.path.endsWith('.conf')) && (_isValidConf(entity.path))) {
String name = path.basenameWithoutExtension(entity.path);
currentVms.add(name);
File pidFile = File(name + '/' + name + '.pid');