Remove old device ID from server in DeviceIDGen

This commit is contained in:
2024-08-12 15:53:40 -04:00
parent e861b2b6f3
commit 7d51d12b55
6 changed files with 48 additions and 26 deletions
+13
View File
@@ -2,6 +2,7 @@ package core
import (
"fmt"
"io/fs"
"os"
"gopkg.in/ini.v1"
@@ -49,6 +50,18 @@ func ParseConfig(valuesRequested [][2]string, missingValueError string) []string
return config
}
// GenDeviceIDList returns a pointer to a slice of all registered device IDs.
// Requires: errorOnFail (set to true to throw an error if the device ID list cannot be generated)
func GenDeviceIDList(errorOnFail bool) *[]fs.DirEntry {
// create a slice of all registered devices
deviceIDList, err := os.ReadDir(ConfigDir + PathSeparator + "devices")
if err != nil && errorOnFail {
fmt.Println(AnsiError + "Failed to read the devices directory: " + err.Error() + AnsiReset)
os.Exit(101)
}
return &deviceIDList
}
// WriteConfig writes the provided key-value pairs under the specified section headers in the libmutton.ini file.
// Requires: valuesToWrite (a slice of length 3 arrays each containing a section, a key name, and a value).
func WriteConfig(valuesToWrite [][3]string, append bool) {