Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort directory entries after they are returned by readdir #2784

Closed
wants to merge 1 commit into from

Conversation

c00w
Copy link

@c00w c00w commented Apr 25, 2019

The readdir syscall does not guarantee a consistent order between calls and on some
file systems this will result in non deterministic store paths for the
same collections of files.

readdir does not guarantee a consistent order between calls and one some
file systems this will result in non deterministic store paths for the
same collections of files.
@edolstra
Copy link
Member

Do you have a specific case where this caused a problem? For example we already sort directory entries in NAR files to ensure a canonical representation.

@c00w
Copy link
Author

c00w commented Apr 25, 2019

Hmmm - Where is that code? I didn't spot any ordering when I was tracing the code paths from nix-store --add, but I definitely may have missed something.

A while ago I was using nix to generate flat os disk images with programs embedded and was frustrated by reruns appearing to not be cached correctly. I was eyeballing the nix code for unrelated reasons and realized that this may have been the root cause (I was on a btrfs file system then). I couldn't reproduce changing hashes via nix-store on ext4, but ext4 actually has consistent readdir semantics due to it's index per folder.

@c00w
Copy link
Author

c00w commented Apr 25, 2019

Tracing the write path though, I definitely see the code running into
https://sourcegraph.com/github.com/NixOS/nix@f22540464fc2e7bbfd441f275b7581f2d4f14eb5/-/blob/src/libutil/archive.cc#L251

so this PR may be redundant with something else that I'm missing.

@c00w
Copy link
Author

c00w commented Apr 25, 2019

Ah - the map iteration at
https://sourcegraph.com/github.com/NixOS/nix@f22540464fc2e7bbfd441f275b7581f2d4f14eb5/-/blob/src/libutil/archive.cc#L87

is guaranteed to be in sorted order per the c++ standard.

@c00w c00w closed this Apr 25, 2019
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.

None yet

2 participants