Allow setting custom device ID prefix

This commit is contained in:
2025-07-06 11:29:41 -04:00
parent 1a66a30bc1
commit fb2120c94e
2 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ func LibmuttonInit(inputCB func(prompt string) string, clientSpecificIniData [][
return errors.New("unable to write config file: " + err.Error())
}
// generate and register device ID
sshEntryRoot, sshIsWindows, err := synccycles.DeviceIDGen(oldDeviceID)
sshEntryRoot, sshIsWindows, err := synccycles.DeviceIDGen(oldDeviceID, "")
if err != nil {
return errors.New("unable to generate device ID: " + err.Error())
}
+6 -4
View File
@@ -16,12 +16,14 @@ import (
// DeviceIDGen generates a new client device ID and registers it with the server (will replace existing one).
// Device IDs are only needed for online synchronization.
// 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 and OS type indicator.
func DeviceIDGen(oldDeviceID string) (string, string, error) {
func DeviceIDGen(oldDeviceID, prefix string) (string, string, error) {
// generate new device ID
deviceIDPrefix, _ := os.Hostname()
deviceIDSuffix := StringGen(rand.Intn(32)+48, 0.2, 1) + "-" + strconv.FormatInt(time.Now().Unix(), 10)
newDeviceID := deviceIDPrefix + "-" + deviceIDSuffix
if prefix == "" {
prefix, _ = os.Hostname()
}
newDeviceID := prefix + "-" + StringGen(rand.Intn(32)+48, 0.2, 1) + "-" + strconv.FormatInt(time.Now().Unix(), 10)
// create new device ID file (locally)
newDeviceIDPath := global.ConfigDir + global.PathSeparator + "devices" + global.PathSeparator + newDeviceID