Switch config format from ini to json (drop ini dependency since json is now used for syncing)

This commit is contained in:
2025-12-17 00:36:20 -05:00
parent e2d1b8dc09
commit b591e2ef5a
11 changed files with 138 additions and 199 deletions
+8 -8
View File
@@ -167,7 +167,7 @@ end:
// Device IDs are guaranteed unique as the current UNIX time is appended to them.
// Leave prefix empty to use the current hostname as the prefix.
// Returns: the remote EntryRoot, the remote AgeDir, and OS type indicator.
func GenDeviceID(oldDeviceID, prefix string) (string, string, string, error) {
func GenDeviceID(oldDeviceID, prefix string) (string, string, bool, error) {
// generate new device ID
if prefix == "" {
prefix, _ = os.Hostname()
@@ -179,7 +179,7 @@ func GenDeviceID(oldDeviceID, prefix string) (string, string, string, error) {
oldDeviceIDPath := global.ConfigDir + global.PathSeparator + "devices" + global.PathSeparator + oldDeviceID
f, err := os.OpenFile(newDeviceIDPath, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", "", "", errors.New("unable to create local device ID file: " + err.Error())
return "", "", false, errors.New("unable to create local device ID file: " + err.Error())
}
_ = f.Close() // error ignored; if the file could be created, it can probably be closed
@@ -201,22 +201,22 @@ func GenDeviceID(oldDeviceID, prefix string) (string, string, string, error) {
sshClient, _, _, _, _, err := GetSSHClient()
if err != nil {
cleanupOnFail()
return "", "", "", errors.New("unable to connect to SSH client: " + err.Error())
return "", "", false, errors.New("unable to connect to SSH client: " + err.Error())
}
output, err := GetSSHOutput(sshClient, "libmuttonserver register", newDeviceID+"\n"+oldDeviceID)
if err != nil {
cleanupOnFail()
return "", "", "", errors.New("unable to register device ID with server: " + err.Error())
return "", "", false, errors.New("unable to register device ID with server: " + err.Error())
}
var registerResp synccommon.RegisterResp
err = json.Unmarshal(output, &registerResp)
if err != nil {
cleanupOnFail()
return "", "", "", errors.New("unable to unmarshal server register response: " + err.Error())
return "", "", false, errors.New("unable to unmarshal server register response: " + err.Error())
}
if registerResp.ErrMsg != nil {
cleanupOnFail()
return "", "", "", errors.New("unable to complete register; server-side error occurred: " + strings.ReplaceAll(*registerResp.ErrMsg, global.FSSpace, "\n"))
return "", "", false, errors.New("unable to complete register; server-side error occurred: " + strings.ReplaceAll(*registerResp.ErrMsg, global.FSSpace, "\n"))
}
_ = sshClient.Close() // ignore error; non-critical/unlikely/not much could be done about it
@@ -224,8 +224,8 @@ func GenDeviceID(oldDeviceID, prefix string) (string, string, string, error) {
err = os.RemoveAll(oldDeviceIDPath)
if err != nil {
cleanupOnFail()
return "", "", "", errors.New("unable to remove old device ID file (locally): " + err.Error())
return "", "", false, errors.New("unable to remove old device ID file (locally): " + err.Error())
}
return registerResp.EntryRoot, registerResp.AgeDir, strconv.FormatBool(registerResp.IsWindows), nil
return registerResp.EntryRoot, registerResp.AgeDir, registerResp.IsWindows, nil
}