Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696565cb12 |
@@ -427,8 +427,8 @@ operands:
|
||||
- A file whose mtime is newer than recorded, or whose size differs, is processed
|
||||
as if new: re-hashed, or recorded without hashes, per the shared-size rule.
|
||||
Change detection compares the mtime to the nanosecond, as finely as the
|
||||
filesystem records it, so a same-size rewrite later in the same second as the
|
||||
recorded mtime still counts as a change.
|
||||
filesystem records it, so a same-size rewrite counts as a change whenever the
|
||||
filesystem gives it a later mtime than recorded, even within the same second.
|
||||
- A database record whose path lies under one of the scanned operands but was
|
||||
not successfully processed this run is deleted. This removes records for
|
||||
deleted files. It also removes records for paths that failed to stat or hash
|
||||
|
||||
+67
-2
@@ -20,6 +20,8 @@ import (
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// writeFile creates a file with the given content and returns its path.
|
||||
@@ -581,6 +583,65 @@ func TestScanContentHashedStalePartners(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestScanContentSameSecondRewrite is TestScanContentStalePartners for
|
||||
// a stored file rewritten in place at the same size with an mtime later
|
||||
// in the same second than recorded: the file counts as changed, so
|
||||
// neither it nor its match inside the operand is read.
|
||||
func TestScanContentSameSecondRewrite(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db := openTestDB(t)
|
||||
dirA := t.TempDir()
|
||||
changed := sparseFileWithoutMatch(t, dirA, "changed", headTailMin)
|
||||
|
||||
first := time.Date(2026, 1, 2, 3, 4, 5, 100_000_000, time.UTC)
|
||||
|
||||
err := os.Chtimes(changed, first, first)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
syncTree(t, db, dirA)
|
||||
|
||||
before := dbRecords(t, db)
|
||||
|
||||
// Rewrite one byte in place, keeping the size.
|
||||
pokeAt(t, changed, headTailMin/2, []byte{1})
|
||||
|
||||
later := first.Add(500 * time.Millisecond)
|
||||
|
||||
err = os.Chtimes(changed, later, later)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dirB := t.TempDir()
|
||||
sparseFile(t, dirB, "changed-copy", headTailMin)
|
||||
|
||||
st := syncTree(t, db, dirB)
|
||||
if st != (scanStats{walked: 1, added: 1}) {
|
||||
t.Errorf("stats = %+v, want 1 added and nothing skipped", st)
|
||||
}
|
||||
|
||||
recs := dbRecords(t, db)
|
||||
for _, r := range recs {
|
||||
if r.content != "" {
|
||||
t.Errorf("%s: content = %q, want none: its only match is stale",
|
||||
r.path, r.content)
|
||||
}
|
||||
}
|
||||
|
||||
for _, old := range before {
|
||||
if r := recordByPath(t, recs, old.path); r != old {
|
||||
t.Errorf("record = %+v, want it left as %+v", r, old)
|
||||
}
|
||||
}
|
||||
|
||||
if groups := dupeGroups(t, db); len(groups) != 0 {
|
||||
t.Errorf("groups = %+v, want none", groups)
|
||||
}
|
||||
}
|
||||
|
||||
// TestScanContentReadFailure checks that a failed content read is
|
||||
// counted as skipped and leaves the record without a content hash, and
|
||||
// that a later scan tries the read again.
|
||||
@@ -1405,9 +1466,13 @@ func TestSyncScanRewriteAfter2262(t *testing.T) {
|
||||
|
||||
// os.Chtimes cannot set this time: it converts through UnixNano.
|
||||
late := time.Date(2300, 1, 2, 3, 4, 5, 0, time.UTC)
|
||||
ts := syscall.Timespec{Sec: late.Unix()}
|
||||
|
||||
err := syscall.UtimesNano(a, []syscall.Timespec{ts, ts})
|
||||
ts, err := unix.TimeToTimespec(late)
|
||||
if err != nil {
|
||||
t.Skipf("%v does not fit this platform's timespec: %v", late, err)
|
||||
}
|
||||
|
||||
err = unix.UtimesNano(a, []unix.Timespec{ts, ts})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user