From 97a9c0a92187685ccfa50260d474a4c7d6bc4c06 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 4 Jun 2024 21:51:58 -0400 Subject: [PATCH] Enforce more consistent meanings for the various field separator characters --- libmuttonserver.go | 6 +++--- src/sync/client.go | 4 ++-- src/sync/common.go | 2 +- src/sync/init.go | 2 +- src/sync/server.go | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libmuttonserver.go b/libmuttonserver.go index 7365c55..d8b6c8e 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -13,8 +13,8 @@ import ( // Field separator key: // \x1d = path separator -// \x1e = space separator -// \x1f = misc. field separator +// \x1e = space/list separator +// \x1f = misc. field separator (if \x1e is already used) func main() { args := os.Args @@ -54,7 +54,7 @@ func main() { // stdin[0] is expected to be the device ID os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + stdin[0]) // print EntryRoot and bool indicating OS type to stdout for client to store in config - fmt.Print(backend.EntryRoot + "\x1f" + strconv.FormatBool(backend.IsWindows)) + fmt.Print(backend.EntryRoot + "\x1e" + strconv.FormatBool(backend.IsWindows)) case "init": // create the necessary directories for libmuttonserver to function backend.DirInit(false) diff --git a/src/sync/client.go b/src/sync/client.go index b4cb897..ad9bf5e 100644 --- a/src/sync/client.go +++ b/src/sync/client.go @@ -143,8 +143,8 @@ func getRemoteDataFromClient(manualSync bool) (map[string]int64, []string, []str } output := GetSSHOutput("libmuttonserver fetch", clientDeviceID[0].Name(), manualSync) - // split output into slice based on occurrences of "\x1d" - outputSlice := strings.Split(output, "\x1d") + // split output into slice based on occurrences of "\x1e" + outputSlice := strings.Split(output, "\x1e") // re-form the lists if len(outputSlice) != 4 { // ensure information from server is complete diff --git a/src/sync/common.go b/src/sync/common.go index f833338..a494cbb 100644 --- a/src/sync/common.go +++ b/src/sync/common.go @@ -40,7 +40,7 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string { if onServer { for _, device := range deviceIDList { if device.Name() != clientDeviceID { - _, err = os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + "\x1d" + strings.ReplaceAll(targetLocationIncomplete, "/", "\x1e")) + _, err = os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + "\x1e" + strings.ReplaceAll(targetLocationIncomplete, "/", "\x1d")) if err != nil { // do not print error as there is currently no way of seeing server-side errors // failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical) diff --git a/src/sync/init.go b/src/sync/init.go index b8143f0..ccfe521 100644 --- a/src/sync/init.go +++ b/src/sync/init.go @@ -18,7 +18,7 @@ func DeviceIDGen() (string, string) { // register device ID with server and fetch remote EntryRoot and OS type //manualSync is true so the user is alerted if device ID registration fails - sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register", deviceID, true), "\x1f") + sshEntryRootSSHIsWindows := strings.Split(GetSSHOutput("libmuttonserver register", deviceID, true), "\x1e") return sshEntryRootSSHIsWindows[0], sshEntryRootSSHIsWindows[1] } diff --git a/src/sync/server.go b/src/sync/server.go index d71bd77..5f31e0f 100644 --- a/src/sync/server.go +++ b/src/sync/server.go @@ -8,7 +8,7 @@ import ( ) // GetRemoteDataFromServer prints to stdout the remote entries, mod times, folders, and deletions -// lists in output are separated by "\x1d" +// lists in output are separated by "\x1e" // output is meant to be captured over SSH for interpretation by the client func GetRemoteDataFromServer(clientDeviceID string) { entryList, dirList := WalkEntryDir() @@ -27,25 +27,25 @@ func GetRemoteDataFromServer(clientDeviceID string) { } // modification time list - fmt.Print("\x1d") + fmt.Print("\x1e") for _, mod := range modList { fmt.Print("\x1f") fmt.Print(mod) } // directory/folder list - fmt.Print("\x1d") + fmt.Print("\x1e") for _, dir := range dirList { fmt.Print("\x1f" + dir) } // deletions list - fmt.Print("\x1d") + fmt.Print("\x1e") for _, deletion := range deletionsList { // print deletion if it is relevant to the current client device - affectedIDTargetLocationIncomplete := strings.Split(deletion.Name(), "\x1d") + affectedIDTargetLocationIncomplete := strings.Split(deletion.Name(), "\x1e") if affectedIDTargetLocationIncomplete[0] == clientDeviceID { - fmt.Print("\x1f" + strings.ReplaceAll(affectedIDTargetLocationIncomplete[1], "\x1e", "/")) + fmt.Print("\x1f" + strings.ReplaceAll(affectedIDTargetLocationIncomplete[1], "\x1d", "/")) // assume successful client deletion and remove deletions file (if assumption is somehow false, worst case scenario is that the client will re-upload the deleted entry) os.Remove(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + deletion.Name())