mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-29 13:26:38 -04:00
Split sync.Rename into separate functions for client and server to avoid compiling SSH into the server binary
This commit is contained in:
+29
-11
@@ -370,17 +370,6 @@ func syncLists(localEntryModMap, remoteEntryModMap map[string]int64, manualSync
|
||||
fmt.Println("Client is synchronized with server")
|
||||
}
|
||||
|
||||
// ShearRemoteFromClient removes the target file or directory from the local system and calls the server to remove it remotely and add it to the deletions list
|
||||
// can safely be called in offline mode, as well, so this is the intended interface for shearing (ShearLocal should only be used directly in the server binary)
|
||||
func ShearRemoteFromClient(targetLocationIncomplete string) {
|
||||
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
|
||||
GetSSHOutput("libmuttonserver shear", deviceID+"\n"+strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1d"), false)
|
||||
|
||||
backend.Exit(0) // sync is not required after shearing since the target has already been removed from the local system
|
||||
}
|
||||
|
||||
// deletionSync removes entries from the client that have been deleted on the server (multi-client deletion)
|
||||
func deletionSync(deletions []string) {
|
||||
var filesDeleted bool
|
||||
@@ -395,7 +384,36 @@ func deletionSync(deletions []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// ShearRemoteFromClient removes the target file or directory from the local system and calls the server to remove it remotely and add it to the deletions list
|
||||
// can safely be called in offline mode, as well, so this is the intended interface for shearing (ShearLocal should only be used directly by the server binary)
|
||||
func ShearRemoteFromClient(targetLocationIncomplete string) {
|
||||
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
|
||||
GetSSHOutput("libmuttonserver shear", deviceID+"\n"+strings.ReplaceAll(targetLocationIncomplete, backend.PathSeparator, "\x1d"), false)
|
||||
|
||||
backend.Exit(0) // sync is not required after shearing since the target has already been removed from the local system
|
||||
}
|
||||
|
||||
// RenameRemoteFromClient renames oldLocationIncomplete to newLocationIncomplete on the local system and calls the server to perform the rename remotely and add the old target to the deletions list
|
||||
// can safely be called in offline mode, as well, so this is the intended interface for renaming (RenameLocal should only be used directly by the server binary)
|
||||
func RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete string) {
|
||||
RenameLocal(oldLocationIncomplete, newLocationIncomplete) // move the target on the local system
|
||||
|
||||
deviceIDList := genDeviceIDList()
|
||||
if len(*deviceIDList) > 0 { // ensure a device ID exists (online mode)
|
||||
// call the server to move the target on the remote system and add the old target to the deletions list
|
||||
GetSSHOutput("libmuttonserver rename",
|
||||
(*deviceIDList)[0].Name()+"\n"+
|
||||
strings.ReplaceAll(oldLocationIncomplete, backend.PathSeparator, "\x1d")+"\n"+
|
||||
strings.ReplaceAll(newLocationIncomplete, backend.PathSeparator, "\x1d"), false)
|
||||
}
|
||||
|
||||
backend.Exit(0)
|
||||
}
|
||||
|
||||
// AddFolderRemoteFromClient creates a new entry-containing directory on the local system and calls the server to create the folder remotely
|
||||
// can safely be called in offline mode, as well, so this is the intended interface for adding folders (AddFolderLocal should only be used directly by the server binary)
|
||||
func AddFolderRemoteFromClient(targetLocationIncomplete string) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user