Implement synchronized renaming

This commit is contained in:
2024-07-09 23:18:13 -04:00
parent 9614ffc513
commit b9ac59fb67
3 changed files with 15 additions and 10 deletions
+7
View File
@@ -40,6 +40,13 @@ func main() {
// 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 // stdin[0] is expected to be the device ID
sync.GetRemoteDataFromServer(stdin[0]) 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": 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
// stdin[0] is expected to be the device ID // stdin[0] is expected to be the device ID
+1 -1
View File
@@ -97,7 +97,7 @@ func main() {
case "note", "-n": case "note", "-n":
field = 4 field = 4
case "rename", "-r": 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: default:
cli.HelpEdit() cli.HelpEdit()
} }
+6 -8
View File
@@ -4,22 +4,20 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
"os" "os"
"os/exec" "os/exec"
"reflect" "reflect"
"strings" "strings"
) )
// RenameCli renames an entry at oldLocation to a new location (user input) // RenameCli renames an entry at oldLocation to a new location (user input) on both the client and the server
func RenameCli(oldLocation string) { func RenameCli(oldLocationIncomplete string) {
// ensure targetLocation exists
backend.TargetIsFile(oldLocation, true, 0)
// prompt user for new location and rename // prompt user for new location and rename
newLocation := backend.TargetLocationFormat(input("New location:")) newLocationIncomplete := input("New location:")
backend.Rename(oldLocation, newLocation) 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) // EditEntryField edits a field of an entry at targetLocation (user input)