Enforce more consistent meanings for the various field separator characters

This commit is contained in:
2024-06-04 21:51:58 -04:00
parent 3c5f508835
commit 9693d2608b
4 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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]
}
+6 -6
View File
@@ -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())