mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-05 16:47:20 -04:00
Server stdin migration: shear
This commit is contained in:
+7
-5
@@ -41,15 +41,17 @@ func main() {
|
|||||||
switch args[1] {
|
switch args[1] {
|
||||||
case "fetch":
|
case "fetch":
|
||||||
// print all information needed for syncing to stdout for interpretation by the client
|
// print all information needed for syncing to stdout for interpretation by the client
|
||||||
|
// stdin[0] is expected to be the device ID
|
||||||
sync.GetRemoteDataFromServer(stdin[0])
|
sync.GetRemoteDataFromServer(stdin[0])
|
||||||
case "shear":
|
case "shear":
|
||||||
// shear an entry from the server and add it to the deletions directory
|
// shear an entry from the server and add it to the deletions directory
|
||||||
deviceIDTargetLocation := strings.Split(args[2], "\x1d")
|
// stdin[0] is expected to be the device ID
|
||||||
targetLocationIncomplete := strings.ReplaceAll(strings.ReplaceAll(deviceIDTargetLocation[1], "\x1f", " "), "\x1e", backend.PathSeparator)
|
// stdin[1] is expected to be the incomplete target location with "\x1d" representing path separators - always pass in UNIX format
|
||||||
sync.ShearLocal(targetLocationIncomplete, deviceIDTargetLocation[0])
|
sync.ShearLocal(strings.ReplaceAll(stdin[1], "\x1d", "/"), stdin[0])
|
||||||
case "addfolder":
|
case "addfolder":
|
||||||
// add a new folder to the server (using information from stdin)
|
// add a new folder to the server
|
||||||
sync.AddFolderLocal(strings.ReplaceAll(stdin[0], "\x1d", backend.PathSeparator))
|
// stdin[0] is expected to be the incomplete target location with "\x1d" representing path separators - always pass in UNIX format
|
||||||
|
sync.AddFolderLocal(strings.ReplaceAll(stdin[0], "\x1d", "/"))
|
||||||
case "register":
|
case "register":
|
||||||
// register a new device ID
|
// register a new device ID
|
||||||
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + args[2])
|
os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + args[2])
|
||||||
|
|||||||
+1
-2
@@ -376,8 +376,7 @@ func ShearRemoteFromClient(targetLocationIncomplete string) {
|
|||||||
deviceID := ShearLocal(targetLocationIncomplete, "") // remove the target from the local system and get the device ID of the client
|
deviceID := ShearLocal(targetLocationIncomplete, "") // remove the target from the local system and get the device ID of the client
|
||||||
|
|
||||||
// call the server to remotely shear the target and add it to the deletions list
|
// 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+"\n"+strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1d"), false)
|
||||||
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
|
os.Exit(0) // sync is not required after shearing since the target has already been removed from the local system
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ func ShearLocal(targetLocationIncomplete, clientDeviceID string) string {
|
|||||||
if onServer {
|
if onServer {
|
||||||
for _, device := range deviceIDList {
|
for _, device := range deviceIDList {
|
||||||
if device.Name() != clientDeviceID {
|
if device.Name() != clientDeviceID {
|
||||||
_, err = os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + "\x1d" + strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1e"))
|
_, err = os.Create(backend.ConfigDir + backend.PathSeparator + "deletions" + backend.PathSeparator + device.Name() + "\x1d" + strings.ReplaceAll(targetLocationIncomplete, "/", "\x1e"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// do not print error as there is currently no way of seeing server-side errors
|
// 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)
|
// failure to add the target to the deletions list will exit the program and result in a client re-uploading the target (non-critical)
|
||||||
|
|||||||
Reference in New Issue
Block a user