From 92187a3b333215fd8c7035bb4bab6c8f15294866 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 10 Feb 2021 16:49:35 +0000 Subject: [PATCH] cmount: fix unicode issues with accented characters on macOS This adds -o modules=iconv,from_code=UTF-8,to_code=UTF-8-MAC To the mount options if it isn't already present which fixes mounting issues on macOS with accented characters in the finder. --- cmd/cmount/mount.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/cmount/mount.go b/cmd/cmount/mount.go index de5691399..94f1084fd 100644 --- a/cmd/cmount/mount.go +++ b/cmd/cmount/mount.go @@ -12,6 +12,7 @@ import ( "fmt" "os" "runtime" + "strings" "sync/atomic" "time" @@ -36,6 +37,19 @@ func init() { mountlib.AddRc("cmount", mount) } +// Find the option string in the current options +func findOption(name string, options []string) (found bool) { + for _, option := range options { + if option == "-o" { + continue + } + if strings.Contains(option, name) { + return true + } + } + return false +} + // mountOptions configures the options from the command line flags func mountOptions(VFS *vfs.VFS, device string, mountpoint string, opt *mountlib.Options) (options []string) { // Options @@ -105,6 +119,13 @@ func mountOptions(VFS *vfs.VFS, device string, mountpoint string, opt *mountlib. for _, option := range opt.ExtraFlags { options = append(options, option) } + if runtime.GOOS == "darwin" { + if !findOption("modules=iconv", options) { + iconv := "modules=iconv,from_code=UTF-8,to_code=UTF-8-MAC" + options = append(options, "-o", iconv) + fs.Debugf(nil, "Adding \"-o %s\" for macOS", iconv) + } + } return options }