diff options
Diffstat (limited to 'backup')
-rw-r--r-- | backup/backup.go | 2 | ||||
-rw-r--r-- | backup/caching_test.go | 62 |
2 files changed, 63 insertions, 1 deletions
diff --git a/backup/backup.go b/backup/backup.go index 84fb554..5e4ffc1 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -108,7 +108,7 @@ func (proc writeDirProcess) writeDir( switch c.Type() { case fs.FFile: - mtime, file_id, ok := pcache.PathUpdated(abspath) + mtime, file_id, ok := pcache.PathUpdated(abspath + "/" + c.Name()) if !ok || mtime.Before(c.ModTime()) { // According to cache the file was changed diff --git a/backup/caching_test.go b/backup/caching_test.go new file mode 100644 index 0000000..6dad62b --- /dev/null +++ b/backup/caching_test.go @@ -0,0 +1,62 @@ +package backup + +import ( + "code.laria.me/petrific/cache" + "code.laria.me/petrific/fs" + "code.laria.me/petrific/objects" + "code.laria.me/petrific/storage/memory" + "testing" + "time" +) + +func TestCacheMTime(t *testing.T) { + c := cache.NewFileCache("") // location doesn't matter here, just use empty string + st := memory.NewMemoryStorage() + filesys := fs.NewMemoryFSRoot("/foo") + + file, err := filesys.CreateChildFile("bar", false) + if err != nil { + t.Fatal(err) + } + + want := file.ModTime() + if _, err := WriteDir(st, "/foo", filesys, c); err != nil { + t.Fatal(err) + } + + have, _, ok := c.PathUpdated("/foo/bar") + if !ok { + t.Fatal("cache doesn't know anything about /foo/bar") + } + + if !have.Equal(want) { + t.Errorf("Unexpected cache time for /foo/bar (want=%s, have=%s)", want, have) + } +} + +func TestCacheRetrieve(t *testing.T) { + c := cache.NewFileCache("") // location doesn't matter here, just use empty string + st := memory.NewMemoryStorage() + filesys := fs.NewMemoryFSRoot("/foo") + + if err := st.Set(objid_emptyfile, objects.OTFile, obj_emptyfile); err != nil { + t.Fatalf("could not set empty file object: %s", err) + } + + file, err := filesys.CreateChildFile("bar", false) + if err != nil { + t.Fatal(err) + } + mfile := file.(*fs.MemfsFile) + + mtime := file.ModTime().Add(1 * time.Hour) + c.SetPathUpdated("/foo/bar", mtime, objid_emptyfile) + + if _, err := WriteDir(st, "/foo", filesys, c); err != nil { + t.Fatal(err) + } + + if mfile.HasBeenRead { + t.Error("/foo/bar has been read by WriteDir") + } +} |