Fix init when no device ID directory exists

This commit is contained in:
2025-06-01 16:40:24 -04:00
parent 4a0e0f8e9e
commit ca4913f054
2 changed files with 7 additions and 5 deletions
+6 -4
View File
@@ -35,10 +35,12 @@ func DeviceIDGen(oldDeviceID string) (string, string, error) {
cleanupOnFail := func() {
// remove new device ID file
os.RemoveAll(newDeviceIDPath)
// restore old device ID file (if it has already been removed due to DirInit)
if isAccessible, _ := back.TargetIsFile(oldDeviceIDPath, true); !isAccessible {
f, _ := os.OpenFile(oldDeviceIDPath, os.O_CREATE|os.O_WRONLY, 0600)
_ = f.Close() // error ignored; if the file could be created, it can probably be closed
if oldDeviceID != global.FSMisc {
// restore old device ID file (if it existed and has already been removed due to DirInit)
if isAccessible, _ := back.TargetIsFile(oldDeviceIDPath, true); !isAccessible {
f, _ := os.OpenFile(oldDeviceIDPath, os.O_CREATE|os.O_WRONLY, 0600)
_ = f.Close() // error ignored; if the file could be created, it can probably be closed
}
}
}