Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
init_journalprogram 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