-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix mv in different filesystems #6280
Fix mv in different filesystems #6280
Conversation
Oh right, always that OSX filesystem link issue. I’ll try to remember how I fixed it last time 😒 |
Note that we shouldn't just replace I think generally we should just avoid moving across filesystems. Where are we doing that? |
The root issue is #6262 in which Nix fails on podman because of some silly overlayfs behavior (https://www.kernel.org/doc/html/latest/filesystems/overlayfs.html?highlight=overlayfs#renaming-directories). More generally, I think this kind of behavior might happen in unexpected places so that’s probably a good idea to have it to prevent Nix from crashing in such a case
Yes you’re right, the fix should be more subtle − both in terms of only using the function in the right places and having a more atomic behavior (maybe copy to a temp location that’s guaranteed to be on the same fs, and then move from it or something like that). |
I suppose we can a I think the "bad news in the name ( |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-27/18433/1 |
00a6dab
to
b97a323
Compare
I may have encountered this, I'm not sure but I'm getting
interestingly it works on my laptop but not server, the Nix version is the same and both have |
@MagicRB That seems to be slightly different (your error is about linking, not moving), but strinkingly similar. What’s the exact context in which you encountered this? (in particular: which kind of command did you rur? and was it in a docker/podman container like in the original issue? )
The chroot should just be a subdir of It looks like the failure comes from here (which is called while building the content of the sandbox). The code already falls back to copying for some error codes, but not for |
Nope this is on NixOS. I can get you the exact command with the rev and everything later. But it was EDIT: I dont remember the rev, but i think that i used the latest so it should be |
b97a323
to
f43517d
Compare
@edolstra I've fixed (I think) the OSX failure. Does that look good? |
e075f9c
to
0b28d7d
Compare
@@ -282,15 +282,6 @@ AC_CHECK_FUNCS([setresuid setreuid lchown]) | |||
AC_CHECK_FUNCS([strsignal posix_fallocate sysconf]) | |||
|
|||
|
|||
# This is needed if bzip2 is a static library, and the Nix libraries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edolstra I've brutally commented that out because it was breaking the libc++fs link (dunno why, but I ended-up with a duplicate symbol error). Do you think it's still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea, I'm fine with removing it, we'll see what breaks :-)
TBH I'm reluctant to start using |
That's a good point (I was actually tripped over that while implementing this PR because although
I'm not married to it though (and it wouldn't fundamentally change this PR), so if you're strongly against it I can rewrite it to use the good ol' Unix APIs (although that would be a non-trivial amount of work, so I'd rather not if possible 🙃 ) |
@edolstra friendly ping on
Any final word on the matter? :) |
Unclutter `util.cc` a bit
Directly takes some c++ strings, and gently throws an exception on error (rather than having to inline this logic everywhere)
In `nix::rename`, if the call to `rename` fails with `EXDEV` (failure because the source and the destination are in a different filesystems) switch to copying and removing the source. To avoid having to re-implement the copy manually, I switched the function to use the c++17 `filesystem` library (which has a `copy` function that should do what we want). Fix NixOS#6262
The recursive copy from the stl doesn’t exactly do what we need because 1. It doesn’t delete things as we go 2. It doesn’t keep the mtime, which change the nars So re-implement it ourselves. A bit dull, but that way we have what we want
Required by the old clang version
`move` tends to have this `mv` connotation of “I will copy it for you if needs be”
In most places the fallback to copying isn’t needed and can actually be bad, so we’d rather not transparently fallback
Rather than directly copying the source to its dest, copy it first to a temporary location, and eventually move that temporary. That way, the move is at least atomic from the point-of-view of the destination
That flag breaks `-lc++fs` (introducing a duplicate symbol for some reason). Besides, it was apparently needed for bzip2, but we're not using bzip2 anymore.
61d4c5c
to
d1cda07
Compare
Doesn't seem needed on a recent-enough clang anymore (and even seems to break stuff)
@edolstra I'm merging this since the |
…lesystems Fix mv in different filesystems
Hopefully fixes #6262 (but I couldn’t manage to reproduce it, so I’m not sure).
This moves things around a bit (well, d4fc2b5 mostly), but the gist of the PR is that calls to
rename
are replaced by a newmoveFile
function which tries the renaming and fallbacks to copying if the filesystems differ (as suggested in containers/podman#13507 (comment) ).I’d love to add some hydra tests for this (or more generally ensuring that the docker image works fine both in docker and podman), but that’ll take a bit more time, so I’ll leave this for later.