Server stdin migration: addfolder

This commit is contained in:
2024-06-04 15:33:50 -04:00
parent 1127e96863
commit 18a8668acf
2 changed files with 13 additions and 5 deletions
+10 -2
View File
@@ -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])
+3 -3
View File
@@ -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)
}