lib/fs: Add case insensitivity to MtimeFS
This is step one of a hundred fifty on the path to case insensitivity. It brings in the basic case folding mechanism and adds it to the mtimefs, as this is something outside the fileset that touches stuff in the database based on name. No effort to convert or handle existing entries when the insensitivity is changed, I don't think we need it... Useless by itself but includes tests and will reduce the review load along the way. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4521
This commit is contained in:
committed by
Audrius Butkevicius
parent
7ebf58f1bc
commit
ee5d0dd43f
@@ -10,6 +10,7 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -80,6 +81,51 @@ func TestMtimeFS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMtimeFSInsensitive(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "darwin", "windows":
|
||||
// blatantly assume file systems here are case insensitive. Might be
|
||||
// a spurious failure on oddly configured systems.
|
||||
default:
|
||||
t.Skip("need case insensitive FS")
|
||||
}
|
||||
|
||||
theTest := func(t *testing.T, fs *MtimeFS, shouldSucceed bool) {
|
||||
os.RemoveAll("testdata")
|
||||
defer os.RemoveAll("testdata")
|
||||
os.Mkdir("testdata", 0755)
|
||||
ioutil.WriteFile("testdata/FiLe", []byte("hello"), 0644)
|
||||
|
||||
// a random time with nanosecond precision
|
||||
testTime := time.Unix(1234567890, 123456789)
|
||||
|
||||
// Do one call that gets struck by an exceptionally evil Chtimes, with a
|
||||
// different case from what is on disk.
|
||||
fs.chtimes = evilChtimes
|
||||
if err := fs.Chtimes("testdata/fIlE", testTime, testTime); err != nil {
|
||||
t.Error("Should not have failed:", err)
|
||||
}
|
||||
|
||||
// Check that we get back the mtime we set, if we were supposed to succed.
|
||||
info, err := fs.Lstat("testdata/FILE")
|
||||
if err != nil {
|
||||
t.Error("Lstat shouldn't fail:", err)
|
||||
} else if info.ModTime().Equal(testTime) != shouldSucceed {
|
||||
t.Errorf("Time mismatch; got %v, comparison %v, expected equal=%v", info.ModTime(), testTime, shouldSucceed)
|
||||
}
|
||||
}
|
||||
|
||||
// The test should fail with a case sensitive mtimefs
|
||||
t.Run("with case sensitive mtimefs", func(t *testing.T) {
|
||||
theTest(t, NewMtimeFS(newBasicFilesystem("."), make(mapStore)), false)
|
||||
})
|
||||
|
||||
// And succeed with a case insensitive one.
|
||||
t.Run("with case insensitive mtimefs", func(t *testing.T) {
|
||||
theTest(t, NewMtimeFS(newBasicFilesystem("."), make(mapStore), WithCaseInsensitivity(true)), true)
|
||||
})
|
||||
}
|
||||
|
||||
// The mapStore is a simple database
|
||||
|
||||
type mapStore map[string][]byte
|
||||
|
||||
Reference in New Issue
Block a user