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.
This commit is contained in:
Nick Craig-Wood 2021-02-10 16:49:35 +00:00
parent 53aa4b87fd
commit 92187a3b33
1 changed files with 21 additions and 0 deletions

View File

@ -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
}