Fix renaming broken symbolic link

Closes: #212

The fix is simply to not follow links when opening a file to be renamed.
O_NOFOLLOW, a non-POSIX extension, does exactly that while not needing
renameat or openat.
This commit is contained in:
Josh Megnauth
2025-09-07 00:50:52 -04:00
committed by Josh Megnauth
parent adc8f9f3b3
commit 55c2e5b8ea
2 changed files with 37 additions and 78 deletions
+4 -1
View File
@@ -908,7 +908,10 @@ impl Pal for Sys {
let newpath = newpath.to_str().map_err(|_| Errno(EINVAL))?;
let newpath = canonicalize(newpath).map_err(|_| Errno(EINVAL))?;
let file = File::open(oldpath, fcntl::O_PATH | fcntl::O_CLOEXEC)?;
let file = File::open(
oldpath,
fcntl::O_NOFOLLOW | fcntl::O_PATH | fcntl::O_CLOEXEC,
)?;
syscall::frename(*file as usize, newpath)?;
Ok(())
}