Swap ownership, fsync race, RowsView memory, renderer regex stack
- A session never unlinks a journal it does not own: Detach, ResetJournal and NotifyFilenameChanged skip removal when this session was locked out or another session holds the lock, and PruneSwapDir skips held journals. A second session used to delete the first session's live journal on save or close. - The writer thread's periodic fsync now runs under mtx_. It fsynced fds that the main thread could close concurrently (or that had been reused); an in-flight fsync also kept a just-closed journal's flock alive, so the owner's own cleanup saw its journal as held. - Compaction locks the compacted file before renaming it into place and keeps using it, so the journal is never unlocked in between; a failed lock on the truncating reopen marks the session locked out. - Unnamed-buffer journals include the pid, so sessions no longer share (and delete) each other's unnamed-N.swp. - RowsView keeps only the previous generation of cached rows: keeping all of them made C-u 2000 M-d on a 1 MiB line use ~2 GB. - Renderers run regex match highlighting through ForEachRegexMatch, which uses the large-stack worker for lines over 512 bytes; some patterns overflowed the main stack well under the previous 10,000 byte limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
@@ -583,3 +583,42 @@ TEST(SwapRecoveryPrompt_LiveJournalOfOtherSession_LeftAlone)
|
||||
other.SetSwapRecorder(nullptr);
|
||||
other_sm.Detach(&other, true);
|
||||
}
|
||||
|
||||
|
||||
// A session locked out of a journal (another session owns it) must not
|
||||
// delete it when it closes or saves the buffer.
|
||||
TEST(SwapJournal_SecondSession_DoesNotDeleteOwnersJournal)
|
||||
{
|
||||
ktet::InstallDefaultCommandsOnce();
|
||||
XdgSandbox sb("owner");
|
||||
const std::string file = (sb.root / "work" / "g.txt").string();
|
||||
write_file_bytes(file, "base\n");
|
||||
|
||||
Editor a;
|
||||
a.SetDimensions(24, 80);
|
||||
std::string err;
|
||||
ASSERT_TRUE(a.OpenFile(file, err));
|
||||
a.CurrentBuffer()->insert_text(0, 0, std::string("A"));
|
||||
a.Swap()->Flush(a.CurrentBuffer());
|
||||
const std::string swp = kte::SwapManager::ComputeSwapPathForTests(*a.CurrentBuffer());
|
||||
ASSERT_TRUE(std::filesystem::exists(swp));
|
||||
|
||||
{
|
||||
Editor b;
|
||||
b.SetDimensions(24, 80);
|
||||
b.AddBuffer(Buffer());
|
||||
b.RequestOpenFile(file);
|
||||
(void) b.ProcessPendingOpens();
|
||||
b.CurrentBuffer()->insert_text(0, 0, std::string("B"));
|
||||
b.Swap()->Flush(b.CurrentBuffer());
|
||||
ASSERT_TRUE(b.CloseBuffer(b.CurrentBufferIndex()));
|
||||
}
|
||||
ASSERT_TRUE(std::filesystem::exists(swp));
|
||||
|
||||
// A's journal still replays to A's content.
|
||||
Buffer check;
|
||||
std::string rerr;
|
||||
ASSERT_TRUE(check.OpenFromFile(file, err));
|
||||
ASSERT_TRUE(kte::SwapManager::ReplayFile(check, swp, rerr));
|
||||
ASSERT_EQ(buffer_bytes_via_views(check), std::string("Abase\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user