Skip to content

Fix Incorrect Mail Journalling#139

Merged
theyoyojo merged 2 commits into
masterfrom
fix
Jul 22, 2024
Merged

Fix Incorrect Mail Journalling#139
theyoyojo merged 2 commits into
masterfrom
fix

Conversation

@charliemirabile

@charliemirabile charliemirabile commented Jul 19, 2024

Copy link
Copy Markdown
Contributor

The init_journal program recreates the journal every time it is run. It does this by reading all the mail files from the mail folder and putting them into a new file and then atomically swapping that file for the old one.

Unfortunately the order that dirents are retrieved from a folder is not deterministic so the order that the email ends up in the journal can vary from one run to the next (especially if new items are added).

This interacts poorly with the assumption that access restriction can consist of just limiting the maximum extant of the journal file that a given user can access because the email will appear within the journal chronologically.

In order to fix this issue, a temporary solution is just to sort all the emails within the journal as the file names will lexicographically sort into the appropriate chronological order.

Fixes: #133

It isn't difficult to determine how big the file will be simply based on
the number of emails written to it. We can avoid a roundtrip to the kernel
to get the length using lseek by just doing our own book-keeping.
The order that files are read from a directory is arbitrary, so the only
way to ensure that the mail is actually listed in chronological order in
the journal is to sort it in place after reading all the mail. Sorting
the file names lexicographically is enough to also achieve chronological
ordering because the timestamps come first, then pids, and then sequence
numbers and the fixed length encoding means that correponding place values
for each are always compared.

@theyoyojo theyoyojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@theyoyojo theyoyojo merged commit f38cd86 into master Jul 22, 2024
@theyoyojo theyoyojo deleted the fix branch July 22, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some emails are visible to users before initial submission deadline

2 participants