diff --git a/internal/sessions/cursor_editor.go b/internal/sessions/cursor_editor.go index 2422a9a2d..83555acae 100644 --- a/internal/sessions/cursor_editor.go +++ b/internal/sessions/cursor_editor.go @@ -54,6 +54,8 @@ func openCursorEditorDB(path string) *sql.DB { // live -wal there is no Cursor running to share it with, and it is opened // as a chat's store is (openCursorStore). func openCursorEditorStore(path string) (*sql.DB, func(), error) { + // copies an older magpie left, which no copy made here would sweep + cursorSnaps.sweep.Do(sweepCursorSnaps) wal, werr := os.Stat(path + "-wal") _, serr := os.Stat(path + "-shm") if !cursorReadInPlace || werr != nil || wal.Size() == 0 || serr != nil { diff --git a/internal/sessions/cursor_snapshot_test.go b/internal/sessions/cursor_snapshot_test.go index 23318fb38..666dcb0a7 100644 --- a/internal/sessions/cursor_snapshot_test.go +++ b/internal/sessions/cursor_snapshot_test.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "sync" "testing" "time" ) @@ -155,7 +156,8 @@ func TestCursorEditorCopiedOncePerChange(t *testing.T) { // copied a ~10.6 GB state.vscdb to the temp folder each time Cursor had // written since the last copy. The store is read where it is, as one more // of the readers Cursor's own processes are: nothing is copied, a row -// Cursor writes is read at once, and Cursor can still write after it. +// Cursor writes is read at once, and Cursor can still write after it. A +// copy an older magpie left is still swept. func TestCursorEditorReadInPlaceWhileLive(t *testing.T) { cursorSetup(t) cursorTempDir(t) @@ -163,6 +165,17 @@ func TestCursorEditorReadInPlaceWhileLive(t *testing.T) { cursorSnapMin = 0 t.Cleanup(func() { cursorSnapMin = minWas }) + // a copy an older magpie left, from before reads were in place + left := filepath.Join(os.TempDir(), "magpie-cursor-left") + if err := os.MkdirAll(left, 0700); err != nil { + t.Fatal(err) + } + old := time.Now().Add(-2 * cursorSnapStale) + if err := os.Chtimes(left, old, old); err != nil { + t.Fatal(err) + } + cursorSnaps.sweep = sync.Once{} + put, ids, at := cursorLiveEditor(t) copies, inPlace := cursorCopies.Load(), cursorInPlace.Load() for round := range 3 {