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
+7 -1
View File
@@ -53,7 +53,8 @@ func GpgKeyGen() string {
}
// DirInit creates the libmutton directories.
func DirInit(preserveOldConfigDir bool) {
// Returns: oldDeviceID (before from before the directory reset).
func DirInit(preserveOldConfigDir bool) string {
// create EntryRoot
err := os.MkdirAll(EntryRoot, 0700)
if err != nil {
@@ -61,6 +62,9 @@ func DirInit(preserveOldConfigDir bool) {
os.Exit(102)
}
// get old device ID before its potential removal
oldDeviceID := (*GenDeviceIDList(false))[0].Name() // errorOnFail set to false to ignore error if device ID directory does not exist (error non-critical for this function)
// remove existing config directory (if it exists and not in append mode)
if !preserveOldConfigDir {
_, isAccessible := TargetIsFile(ConfigDir, false, 1)
@@ -79,4 +83,6 @@ func DirInit(preserveOldConfigDir bool) {
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\": " + err.Error() + AnsiReset)
os.Exit(102)
}
return oldDeviceID
}