From 82b1e31e5b6c0fbdf379c5fc60bef089e8528938 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Wed, 10 Jul 2024 15:23:13 -0400 Subject: [PATCH] Replace use of ASCII control characters with unicode characters allowed in Windows filenames (fixes shearing with a Windows server) --- completions/powershell7plus/mutn.ps1 | 6 +++--- libmuttonserver.go | 21 ++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/completions/powershell7plus/mutn.ps1 b/completions/powershell7plus/mutn.ps1 index ac094a0..3ae9beb 100644 --- a/completions/powershell7plus/mutn.ps1 +++ b/completions/powershell7plus/mutn.ps1 @@ -4,7 +4,7 @@ function cliMUTNEntryCompleter { $mutnPath = (Resolve-Path '~\AppData\Local\libmutton\entries').Path try { $trimmedPaths = If (Test-Path $mutnPath) { - (Get-ChildItem -Path $mutnPath -Recurse -File).FullName.Substring($mutnPath.Length) -replace '\\', '/' -replace ' ', [char]0x23bd + (Get-ChildItem -Path $mutnPath -Recurse -File).FullName.Substring($mutnPath.Length) -replace '\\', '/' -replace ' ', [char]0x259d } } catch { $trimmedPaths = $null # if any errors occur (especially, "You cannot call a method on a null-valued expression", set $trimmedPaths to $null @@ -50,6 +50,6 @@ function mutn { [string]$option ) - #Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` ' -replace [char]0x1a, '` '), $argument, $option).Trim() # UNIX testing - Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` ' -replace [char]0x23bd, '` '), $argument, $option).Trim() + #Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` ' -replace [char]0x259d, '` '), $argument, $option).Trim() # UNIX testing + Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` ' -replace [char]0x259d, '` '), $argument, $option).Trim() } diff --git a/libmuttonserver.go b/libmuttonserver.go index 4272c15..d5535c7 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -11,11 +11,6 @@ import ( "strings" ) -// Field separator key: -// \x1d = path separator -// \x1e = space/list separator -// \x1f = misc. field separator (if \x1e is already used) - func main() { args := os.Args if len(args) < 2 { @@ -43,25 +38,25 @@ func main() { 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.RenameLocal(strings.ReplaceAll(stdin[1], "\x1d", "/"), strings.ReplaceAll(stdin[2], "\x1d", "/")) + // stdin[1] is expected to be the OLD incomplete target location with FSPath representing path separators - always pass in UNIX format + // stdin[2] is expected to be the NEW incomplete target location with FSPath representing path separators - always pass in UNIX format + sync.RenameLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), strings.ReplaceAll(stdin[2], sync.FSPath, "/")) 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 - // stdin[1] is expected to be the incomplete target location with "\x1d" representing path separators - always pass in UNIX format - sync.ShearLocal(strings.ReplaceAll(stdin[1], "\x1d", "/"), stdin[0]) + // stdin[1] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format + sync.ShearLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), stdin[0]) case "addfolder": // add a new folder to the server - // 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", "/")) + // stdin[0] is expected to be the incomplete target location with FSPath representing path separators - always pass in UNIX format + sync.AddFolderLocal(strings.ReplaceAll(stdin[0], sync.FSPath, "/")) case "register": // register a new device ID // stdin[0] is expected to be the device ID _, _ = os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + stdin[0]) // error ignored; failure unlikely to occur if init was successful; "register" is not a user-facing argument and thus the error would not be visible // print EntryRoot and bool indicating OS type to stdout for client to store in config - fmt.Print(backend.EntryRoot + "\x1e" + strconv.FormatBool(backend.IsWindows)) + fmt.Print(backend.EntryRoot + sync.FSSpace + strconv.FormatBool(backend.IsWindows)) case "init": // create the necessary directories for libmuttonserver to function backend.DirInit(false)