Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize NFD filenames on OS X #8

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions fsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"path/filepath"
"runtime"

"golang.org/x/text/unicode/norm"

"github.com/spf13/afero"
)

Expand Down Expand Up @@ -180,24 +182,35 @@ func (s *Syncer) sync(dst, src string) {
// deletion below
m := make(map[string]bool, len(files))
for _, file := range files {
dst2 := filepath.Join(dst, file.Name())
src2 := filepath.Join(src, file.Name())
filename := normalizeFilename(file.Name())

dst2 := filepath.Join(dst, filename)
src2 := filepath.Join(src, filename)
s.sync(dst2, src2)
m[file.Name()] = true
m[filename] = true
}

// delete files from dst that does not exist in src
if s.Delete {
files, err = afero.ReadDir(s.DestFs, dst)
check(err)
for _, file := range files {
if !m[file.Name()] {
check(s.DestFs.RemoveAll(filepath.Join(dst, file.Name())))
filename := normalizeFilename(file.Name())
if !m[filename] {
check(s.DestFs.RemoveAll(filepath.Join(dst, filename)))
}
}
}
}

func normalizeFilename(filename string) string {
if runtime.GOOS == "darwin" {
// When a file system is HFS+, its filepath is in NFD form.
return norm.NFC.String(filename)
}
return filename
}

// syncstats makes sure dst has the same pemissions and modification time as src
func (s *Syncer) syncstats(dst, src string) {
// get file infos; return if not exist and panic if error
Expand Down