lib/ignore: Fast reload of unchanged ignores (fixes #3394)
This changes the "seen" map that we're anyway keeping around to track the modtimes of loaded files instead. When doing a Load() we check that 1) the file we are loading is in the modtime set, and 2) that none of the files in the modtime set have changed modtimes. If that's the case we do a quick return without parsing anything or clearing the cache. This required adding two one seconds sleeps in the tests to make sure the modtimes were updated when we expect cache reloads, because I'm on a crappy filesystem with one second timestamp granularity. That also proves it works... GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3754
This commit is contained in:
committed by
Audrius Butkevicius
parent
5bb74ee61c
commit
a2b8485a89
@@ -14,6 +14,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIgnore(t *testing.T) {
|
||||
@@ -276,9 +277,12 @@ func TestCaching(t *testing.T) {
|
||||
t.Fatal("Expected 4 cached results")
|
||||
}
|
||||
|
||||
// Modify the include file, expect empty cache
|
||||
// Modify the include file, expect empty cache. Ensure the timestamp on
|
||||
// the file changes.
|
||||
|
||||
time.Sleep(time.Second)
|
||||
fd2.WriteString("/z/\n")
|
||||
fd2.Sync()
|
||||
|
||||
err = pats.Load(fd1.Name())
|
||||
if err != nil {
|
||||
@@ -307,7 +311,9 @@ func TestCaching(t *testing.T) {
|
||||
|
||||
// Modify the root file, expect cache to be invalidated
|
||||
|
||||
time.Sleep(time.Second)
|
||||
fd1.WriteString("/a/\n")
|
||||
fd1.Sync()
|
||||
|
||||
err = pats.Load(fd1.Name())
|
||||
if err != nil {
|
||||
@@ -472,6 +478,8 @@ func TestCacheReload(t *testing.T) {
|
||||
|
||||
// Rewrite file to match f1 and f3
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
err = fd.Truncate(0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user