فهرست منبع

Move filename conversion into osutil

Audrius Butkevicius 11 سال پیش
والد
کامیت
c891999e1d

+ 2 - 1
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
 			}
 		}

+ 9 - 8
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")

+ 3 - 3
internal/files/filenames_darwin.go → 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 <http://www.gnu.org/licenses/>.
 
-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)
 }

+ 3 - 3
internal/files/filenames_unix.go → 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
 }

+ 3 - 3
internal/files/filenames_windows.go → 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 <http://www.gnu.org/licenses/>.
 
-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)
 }