From b9ac59fb6740443a8b42451082f9922183352418 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 9 Jul 2024 23:18:13 -0400 Subject: [PATCH] Implement synchronized renaming --- libmuttonserver.go | 9 ++++++++- mutn.go | 2 +- src/cli/edit.go | 14 ++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libmuttonserver.go b/libmuttonserver.go index 8856201..eff79f8 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -40,6 +40,13 @@ func main() { // 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]) + case "rename": + // move an entry to a new location before using fallthrough to add its previous iteration to the deletions directory + // stdin[0] is evaluated after fallthrough + // stdin[1] is expected to be the OLD incomplete target location with "\x1d" representing path separators - always pass in UNIX format + // stdin[2] is expected to be the NEW incomplete target location with "\x1d" representing path separators - always pass in UNIX format + sync.Rename(strings.ReplaceAll(stdin[1], "\x1d", "/"), strings.ReplaceAll(stdin[2], "\x1d", "/"), true) + fallthrough // fallthrough to add the old entry to the deletions directory case "shear": // shear an entry from the server and add it to the deletions directory // stdin[0] is expected to be the device ID @@ -73,7 +80,7 @@ This software exists under the MIT license; you may redistribute it under certai This program comes with absolutely no warranty; type "libmuttonserver version" for details. ` + cli.AnsiBold + "Usage:" + backend.AnsiReset + ` libmuttonserver - + ` + cli.AnsiBold + "Arguments (user):" + backend.AnsiReset + ` help|-h Bring up this menu version|-v Display version and license information diff --git a/mutn.go b/mutn.go index 175e4fd..a4447ae 100644 --- a/mutn.go +++ b/mutn.go @@ -97,7 +97,7 @@ func main() { case "note", "-n": field = 4 case "rename", "-r": - cli.RenameCli(targetLocation) + cli.RenameCli(args[1]) // pass the incomplete path as the server and all clients (reading from the deletions directory) will have a different home directory default: cli.HelpEdit() } diff --git a/src/cli/edit.go b/src/cli/edit.go index 583f967..69328e9 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -4,22 +4,20 @@ import ( "bufio" "fmt" "github.com/rwinkhart/MUTN/src/backend" + "github.com/rwinkhart/MUTN/src/sync" "os" "os/exec" "reflect" "strings" ) -// RenameCli renames an entry at oldLocation to a new location (user input) -func RenameCli(oldLocation string) { - // ensure targetLocation exists - backend.TargetIsFile(oldLocation, true, 0) - +// RenameCli renames an entry at oldLocation to a new location (user input) on both the client and the server +func RenameCli(oldLocationIncomplete string) { // prompt user for new location and rename - newLocation := backend.TargetLocationFormat(input("New location:")) - backend.Rename(oldLocation, newLocation) + newLocationIncomplete := input("New location:") + sync.Rename(oldLocationIncomplete, newLocationIncomplete, false) - // exit is done from backend.Rename + // exit is done from sync.Rename } // EditEntryField edits a field of an entry at targetLocation (user input)