From c891999e1d718f730f941f0f65bd98f41e4be54c Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Wed, 5 Nov 2014 23:41:51 +0000 Subject: [PATCH] Move filename conversion into osutil --- internal/files/blockmap.go | 3 ++- internal/files/set.go | 17 +++++++++-------- internal/{files => osutil}/filenames_darwin.go | 6 +++--- internal/{files => osutil}/filenames_unix.go | 6 +++--- internal/{files => osutil}/filenames_windows.go | 6 +++--- 5 files changed, 20 insertions(+), 18 deletions(-) rename internal/{files => osutil}/filenames_darwin.go (89%) rename internal/{files => osutil}/filenames_unix.go (89%) rename internal/{files => osutil}/filenames_windows.go (89%) diff --git a/internal/files/blockmap.go b/internal/files/blockmap.go index d47fe9db2..618f44f4e 100644 --- a/internal/files/blockmap.go +++ b/internal/files/blockmap.go @@ -29,6 +29,7 @@ import ( "sync" "github.com/syncthing/syncthing/internal/config" + "github.com/syncthing/syncthing/internal/osutil" "github.com/syncthing/syncthing/internal/protocol" "github.com/syndtr/goleveldb/leveldb" @@ -171,7 +172,7 @@ func (f *BlockFinder) Iterate(hash []byte, iterFn func(string, string, uint32) b for iter.Next() && iter.Error() == nil { folder, file := fromBlockKey(iter.Key()) index := binary.BigEndian.Uint32(iter.Value()) - if iterFn(folder, nativeFilename(file), index) { + if iterFn(folder, osutil.NativeFilename(file), index) { return true } } diff --git a/internal/files/set.go b/internal/files/set.go index 01cc517c0..730a55d88 100644 --- a/internal/files/set.go +++ b/internal/files/set.go @@ -25,6 +25,7 @@ import ( "sync" "github.com/syncthing/syncthing/internal/lamport" + "github.com/syncthing/syncthing/internal/osutil" "github.com/syncthing/syncthing/internal/protocol" "github.com/syndtr/goleveldb/leveldb" ) @@ -174,19 +175,19 @@ func (s *Set) WithGlobalTruncated(fn fileIterator) { } func (s *Set) Get(device protocol.DeviceID, file string) protocol.FileInfo { - f := ldbGet(s.db, []byte(s.folder), device[:], []byte(normalizedFilename(file))) - f.Name = nativeFilename(f.Name) + f := ldbGet(s.db, []byte(s.folder), device[:], []byte(osutil.NormalizedFilename(file))) + f.Name = osutil.NativeFilename(f.Name) return f } func (s *Set) GetGlobal(file string) protocol.FileInfo { - f := ldbGetGlobal(s.db, []byte(s.folder), []byte(normalizedFilename(file))) - f.Name = nativeFilename(f.Name) + f := ldbGetGlobal(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file))) + f.Name = osutil.NativeFilename(f.Name) return f } func (s *Set) Availability(file string) []protocol.DeviceID { - return ldbAvailability(s.db, []byte(s.folder), []byte(normalizedFilename(file))) + return ldbAvailability(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file))) } func (s *Set) LocalVersion(device protocol.DeviceID) uint64 { @@ -213,7 +214,7 @@ func DropFolder(db *leveldb.DB, folder string) { func normalizeFilenames(fs []protocol.FileInfo) { for i := range fs { - fs[i].Name = normalizedFilename(fs[i].Name) + fs[i].Name = osutil.NormalizedFilename(fs[i].Name) } } @@ -221,10 +222,10 @@ func nativeFileIterator(fn fileIterator) fileIterator { return func(fi protocol.FileIntf) bool { switch f := fi.(type) { case protocol.FileInfo: - f.Name = nativeFilename(f.Name) + f.Name = osutil.NativeFilename(f.Name) return fn(f) case protocol.FileInfoTruncated: - f.Name = nativeFilename(f.Name) + f.Name = osutil.NativeFilename(f.Name) return fn(f) default: panic("unknown interface type") diff --git a/internal/files/filenames_darwin.go b/internal/osutil/filenames_darwin.go similarity index 89% rename from internal/files/filenames_darwin.go rename to internal/osutil/filenames_darwin.go index 4d2559cc7..ce8c40858 100644 --- a/internal/files/filenames_darwin.go +++ b/internal/osutil/filenames_darwin.go @@ -13,14 +13,14 @@ // You should have received a copy of the GNU General Public License along // with this program. If not, see . -package files +package osutil import "code.google.com/p/go.text/unicode/norm" -func normalizedFilename(s string) string { +func NormalizedFilename(s string) string { return norm.NFC.String(s) } -func nativeFilename(s string) string { +func NativeFilename(s string) string { return norm.NFD.String(s) } diff --git a/internal/files/filenames_unix.go b/internal/osutil/filenames_unix.go similarity index 89% rename from internal/files/filenames_unix.go rename to internal/osutil/filenames_unix.go index 573069c17..7741f6176 100644 --- a/internal/files/filenames_unix.go +++ b/internal/osutil/filenames_unix.go @@ -15,14 +15,14 @@ // +build !windows,!darwin -package files +package osutil import "code.google.com/p/go.text/unicode/norm" -func normalizedFilename(s string) string { +func NormalizedFilename(s string) string { return norm.NFC.String(s) } -func nativeFilename(s string) string { +func NativeFilename(s string) string { return s } diff --git a/internal/files/filenames_windows.go b/internal/osutil/filenames_windows.go similarity index 89% rename from internal/files/filenames_windows.go rename to internal/osutil/filenames_windows.go index 34a37a9ea..88ba71ba3 100644 --- a/internal/files/filenames_windows.go +++ b/internal/osutil/filenames_windows.go @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License along // with this program. If not, see . -package files +package osutil import ( "path/filepath" @@ -21,10 +21,10 @@ import ( "code.google.com/p/go.text/unicode/norm" ) -func normalizedFilename(s string) string { +func NormalizedFilename(s string) string { return norm.NFC.String(filepath.ToSlash(s)) } -func nativeFilename(s string) string { +func NativeFilename(s string) string { return filepath.FromSlash(s) }