From 18a8668acfdee08024a73983fde1e8f3cd9619a4 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 4 Jun 2024 15:33:50 -0400 Subject: [PATCH] Server stdin migration: addfolder --- libmuttonserver.go | 12 ++++++++++-- src/sync/client.go | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libmuttonserver.go b/libmuttonserver.go index 52fc178..dbb0161 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -28,6 +28,14 @@ func main() { for scanner.Scan() { stdin = append(stdin, scanner.Text()) } + + // TODO debug, remove!! + // write stdin to file + //f, _ := os.Create(backend.ConfigDir + backend.PathSeparator + "stdindebug.txt") + //for _, line := range stdin { + // f.WriteString(line + "\n") + //} + //f.Close() } switch args[1] { @@ -40,8 +48,8 @@ func main() { targetLocationIncomplete := strings.ReplaceAll(strings.ReplaceAll(deviceIDTargetLocation[1], "\x1f", " "), "\x1e", backend.PathSeparator) sync.ShearLocal(targetLocationIncomplete, deviceIDTargetLocation[0]) case "addfolder": - // add a new folder to the server - sync.AddFolderLocal(strings.ReplaceAll(args[2], "\x1f", " ")) + // add a new folder to the server (using information from stdin) + sync.AddFolderLocal(strings.ReplaceAll(stdin[0], "\x1d", backend.PathSeparator)) case "register": // register a new device ID os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + args[2]) diff --git a/src/sync/client.go b/src/sync/client.go index 051cbc7..5ab52b9 100644 --- a/src/sync/client.go +++ b/src/sync/client.go @@ -377,7 +377,7 @@ func ShearRemoteFromClient(targetLocationIncomplete string) { // call the server to remotely shear the target and add it to the deletions list // deviceID and targetLocationIncomplete are separated by \x1d, path separators are replaced with \x1e, and spaces are replaced with \x1f TODO is there a need to combine deviceID and targetLocationIncomplete into one argument? - GetSSHOutput("libmuttonserver shear "+deviceID+"\x1d"+strings.ReplaceAll(strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1e"), " ", "\x1f"), "", false) // TODO seems to already have Windows server support, perhaps copy this approach to AddFolderRemoteFromClient + GetSSHOutput("libmuttonserver shear "+deviceID+"\x1d"+strings.ReplaceAll(strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1e"), " ", "\x1f"), "", false) os.Exit(0) // sync is not required after shearing since the target has already been removed from the local system } @@ -398,8 +398,8 @@ func deletionSync(deletions []string) { // AddFolderRemoteFromClient creates a new entry-containing directory on the local system and calls the server to create the folder remotely func AddFolderRemoteFromClient(targetLocationIncomplete string) { - AddFolderLocal(targetLocationIncomplete) // add the folder on the local system - GetSSHOutput("libmuttonserver addfolder "+strings.ReplaceAll(targetLocationIncomplete, " ", "\x1f"), "", false) // call the server to create the folder remotely TODO Windows server support + AddFolderLocal(targetLocationIncomplete) // add the folder on the local system + GetSSHOutput("libmuttonserver addfolder", strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1d"), false) // call the server to create the folder remotely os.Exit(0) }