mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Enforce more consistent meanings for the various field separator characters
This commit is contained in:
+3
-3
@@ -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)
|
||||
|
||||
+2
-2
@@ -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
@@ -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
@@ -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
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user