Replace use of ASCII control characters with unicode characters allowed in Windows filenames (fixes shearing with a Windows server)

This commit is contained in:
2024-07-10 15:23:13 -04:00
parent 0ebc404db2
commit 82b1e31e5b
2 changed files with 11 additions and 16 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ function cliMUTNEntryCompleter {
$mutnPath = (Resolve-Path '~\AppData\Local\libmutton\entries').Path $mutnPath = (Resolve-Path '~\AppData\Local\libmutton\entries').Path
try { try {
$trimmedPaths = If (Test-Path $mutnPath) { $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 { } catch {
$trimmedPaths = $null # if any errors occur (especially, "You cannot call a method on a null-valued expression", set $trimmedPaths to $null $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 [string]$option
) )
#Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` ' -replace [char]0x1a, '` '), $argument, $option).Trim() # UNIX testing #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]0x23bd, '` '), $argument, $option).Trim() Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` ' -replace [char]0x259d, '` '), $argument, $option).Trim()
} }
+8 -13
View File
@@ -11,11 +11,6 @@ import (
"strings" "strings"
) )
// Field separator key:
// \x1d = path separator
// \x1e = space/list separator
// \x1f = misc. field separator (if \x1e is already used)
func main() { func main() {
args := os.Args args := os.Args
if len(args) < 2 { if len(args) < 2 {
@@ -43,25 +38,25 @@ func main() {
case "rename": case "rename":
// move an entry to a new location before using fallthrough to add its previous iteration to the deletions directory // 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[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[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 "\x1d" 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], "\x1d", "/"), strings.ReplaceAll(stdin[2], "\x1d", "/")) 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 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
// stdin[1] is expected to be the incomplete target location with "\x1d" representing path separators - always pass in UNIX format // 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], "\x1d", "/"), stdin[0]) sync.ShearLocal(strings.ReplaceAll(stdin[1], sync.FSPath, "/"), stdin[0])
case "addfolder": case "addfolder":
// add a new folder to the server // 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 // 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], "\x1d", "/")) sync.AddFolderLocal(strings.ReplaceAll(stdin[0], sync.FSPath, "/"))
case "register": case "register":
// register a new device ID // register a new device ID
// stdin[0] is expected to be the 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 _, _ = 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 // 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": case "init":
// create the necessary directories for libmuttonserver to function // create the necessary directories for libmuttonserver to function
backend.DirInit(false) backend.DirInit(false)