dirent: a folder renamed in whole under a watched one's name is read again
A listing was taken as current unless its own folder or its root's was
heard to change. A folder replaced whole (renamed away, another renamed
in under its name) is heard only in the folder that holds it, so a
Sessions read kept the old folder's listing until listedFor ran out.
Found while dropping WatchRoot (the commit before), which never covered
this: it reports the root alone. Every folder from the listing's parent
up to its root is now checked.
Run (mote, at this tree):
- go test -race -count=5 ./internal/dirent: ok
- go test ./internal/sessions: ok
- go vet ./internal/dirent for linux, windows; gofmt -l: clean
- red on the old code: the same rename as TestFolderReplacedWholeIsReadAgain,
3 of 3 "new file not seen" at 0522bf84f.
Not tried: the full suite (CI runs it).
This commit is contained in:
@@ -364,12 +364,21 @@ func current(dir string, l Listing) bool {
|
||||
if watched.dirty[dir] >= at.seq {
|
||||
return false
|
||||
}
|
||||
// a change in a root's own folder is word of a change anywhere under
|
||||
// it: Codex appends history.jsonl, closed each time, at each prompt,
|
||||
// while the rollout it writes stays open and unheard
|
||||
// a change in a folder above dir, up to its root's own, is word of a
|
||||
// change in dir: a folder renamed in whole under dir's name is heard
|
||||
// only in the folder that holds it, and Codex appends history.jsonl,
|
||||
// in the root, at each prompt while the rollout it writes stays open
|
||||
// and unheard
|
||||
for _, r := range watched.roots {
|
||||
if (within(dir, r.given) || within(dir, r.real)) && (watched.dirty[r.given] >= at.seq || watched.dirty[r.real] >= at.seq) {
|
||||
return false
|
||||
for _, top := range [2]string{r.given, r.real} {
|
||||
if !within(dir, top) {
|
||||
continue
|
||||
}
|
||||
for p := dir; len(p) > len(top); p = filepath.Dir(p) {
|
||||
if watched.dirty[filepath.Dir(p)] >= at.seq {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -221,3 +221,37 @@ func TestRootReplacedWholeIsReadAgain(t *testing.T) {
|
||||
t.Fatal("the new root's folder was read on every Stats after it settled")
|
||||
}
|
||||
}
|
||||
|
||||
// A folder under the root replaced whole, renamed in under its name, is
|
||||
// heard only in the folder that holds it: the next read lists the new
|
||||
// folder, not the old one's listing.
|
||||
func TestFolderReplacedWholeIsReadAgain(t *testing.T) {
|
||||
root, day, _ := dayFolder(t)
|
||||
if !quiet(t, root, day) {
|
||||
t.Fatal("an unchanged watched folder was read again")
|
||||
}
|
||||
other := filepath.Join(t.TempDir(), "12")
|
||||
if err := os.Mkdir(other, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := filepath.Join(other, "rollout-b.jsonl")
|
||||
if err := os.WriteFile(b, []byte("{}\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aged(t, b)
|
||||
if err := os.Rename(day, day+".old"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Rename(other, day); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := sizeOf(t, root, day, "rollout-b.jsonl"); !ok {
|
||||
t.Fatal("the new folder's file wasn't seen")
|
||||
}
|
||||
if _, ok := sizeOf(t, root, day, "rollout-a.jsonl"); ok {
|
||||
t.Fatal("the old folder's file was still listed")
|
||||
}
|
||||
if !quiet(t, root, day) {
|
||||
t.Fatal("the new folder was read on every Stats after it settled")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user