Skip to content

Commit

Permalink
Merge pull request #64 from sunfishcode/sunfishcode/renameat2-norepla…
Browse files Browse the repository at this point in the history
…ce-einval

Handle filesystems that don't support `RENAME_NOREPLACE`.
  • Loading branch information
sunfishcode authored Sep 19, 2024
2 parents 8a9b6da + b0c42da commit 4c3ae28
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,20 @@ mod imp {
}
return Ok(());
}
Err(rustix::io::Errno::NOSYS) => {
// The OS doesn't support `renameat2`; remember this so
// that we don't bother calling it again.
Err(rustix::io::Errno::INVAL) | Err(rustix::io::Errno::NOSYS) => {
// `NOSYS` means the OS doesn't support `renameat2`;
// remember this so that we don't bother calling it
// again.
//
// `INVAL` might mean we're on a filesystem that
// doesn't support the `NOREPLACE` flag, such as ZFS,
// so let's conservatively avoid using `renameat2`
// again as well.
//
// (Or, `INVAL` might mean that the user is trying to
// make a directory a subdirectory of itself, in which
// case responding by disabling further use of
// `renameat2` is unfortunate but what else can we do?)
NO_RENAMEAT2.store(true, Relaxed);
}
Err(e) => return Err(e.into()),
Expand Down

0 comments on commit 4c3ae28

Please sign in to comment.