mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-03 07:37:28 -04:00
Fix init when no device ID directory exists
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ func DirInit(preserveOldConfigDir bool) (string, error) {
|
|||||||
// get old device ID before its potential removal
|
// get old device ID before its potential removal
|
||||||
oldDeviceID, err := GetCurrentDeviceID()
|
oldDeviceID, err := GetCurrentDeviceID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("unable to get current device ID: " + err.Error())
|
oldDeviceID = FSMisc
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove existing config directory (if it exists and not in append mode)
|
// remove existing config directory (if it exists and not in append mode)
|
||||||
|
|||||||
+6
-4
@@ -35,10 +35,12 @@ func DeviceIDGen(oldDeviceID string) (string, string, error) {
|
|||||||
cleanupOnFail := func() {
|
cleanupOnFail := func() {
|
||||||
// remove new device ID file
|
// remove new device ID file
|
||||||
os.RemoveAll(newDeviceIDPath)
|
os.RemoveAll(newDeviceIDPath)
|
||||||
// restore old device ID file (if it has already been removed due to DirInit)
|
if oldDeviceID != global.FSMisc {
|
||||||
if isAccessible, _ := back.TargetIsFile(oldDeviceIDPath, true); !isAccessible {
|
// restore old device ID file (if it existed and has already been removed due to DirInit)
|
||||||
f, _ := os.OpenFile(oldDeviceIDPath, os.O_CREATE|os.O_WRONLY, 0600)
|
if isAccessible, _ := back.TargetIsFile(oldDeviceIDPath, true); !isAccessible {
|
||||||
_ = f.Close() // error ignored; if the file could be created, it can probably be closed
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user