mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 04:46:42 -04:00
Break current device ID retrieval out into exported function GetCurrentDeviceID(); fix duplicate device IDs being generated by not deleting the old one before a potentially failed registration
This commit is contained in:
+14
-7
@@ -60,13 +60,7 @@ func DirInit(preserveOldConfigDir bool) string {
|
||||
}
|
||||
|
||||
// get old device ID before its potential removal
|
||||
oldDeviceIDList := GenDeviceIDList(false) // errorOnFail is false so that nil is received when the devices directory does not exist
|
||||
var oldDeviceID string
|
||||
if oldDeviceIDList != nil && len(*oldDeviceIDList) > 0 { // ensure not derferencing nil, which occurs when the devices directory does not exist
|
||||
oldDeviceID = (*oldDeviceIDList)[0].Name()
|
||||
} else {
|
||||
oldDeviceID = FSMisc // indicates to server that no device ID is being replaced
|
||||
}
|
||||
oldDeviceID := GetCurrentDeviceID()
|
||||
|
||||
// remove existing config directory (if it exists and not in append mode)
|
||||
if !preserveOldConfigDir {
|
||||
@@ -87,3 +81,16 @@ func DirInit(preserveOldConfigDir bool) string {
|
||||
|
||||
return oldDeviceID
|
||||
}
|
||||
|
||||
// GetOldDeviceID returns the current device ID or
|
||||
// FSMisc if there is no device ID (e.g. first run).
|
||||
func GetCurrentDeviceID() string {
|
||||
deviceIDList := GenDeviceIDList(false) // errorOnFail is false so that nil is received when the devices directory does not exist
|
||||
var deviceID string
|
||||
if deviceIDList != nil && len(*deviceIDList) > 0 { // ensure not derferencing nil, which occurs when the devices directory does not exist
|
||||
deviceID = (*deviceIDList)[0].Name()
|
||||
} else {
|
||||
deviceID = FSMisc // indicates to server that no device ID is being replaced
|
||||
}
|
||||
return deviceID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user