Description
Problem
When the cargo project directory is in vboxsf file system (VirtualBox shared folder) that is shared from host Windows system to guest Linux, then the cargo add <crate>
command fails with the error:
error: failed to persist temporary file: Text file busy (os error 26)
I noticed this after upgrading to rust 1.76.0, but the regression may have been there in 1.75.0 too.
The cargo add was working in older versions inside a vboxsf shared directory.
Steps
- In VirtualBox Linux guest system, go to a cargo project inside a vboxsf shared directory from Windows host system.
- Execute cargo add command.
- The error is printed, the
Cargo.toml
file is not updated, and a temporary file (e.g.Cargo.tomln1aoHw
) is left into directory.
Possible Solution(s)
The regression is probably caused by the change #12744, which introduces write_atomic
function that uses the tempfile
crate. The tempfile crate assumes "unix semantics", that files can be unlinked and renamed while holding a file descriptor to them. However, in the case of vboxsf filesystem shared from Windows, the files cannot be either renamed or unlinked while having an open file descriptor to them.
Debugging with strace
shows that the rename and unlink calls are done between open and close:
openat(AT_FDCWD, "/media/vboxsf/.../Cargo.tomleN6hA9", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = 3
write(3, "[package]\nname = "..., 241) = 241
renameat(AT_FDCWD, "/media/vboxsf/.../Cargo.tomleN6hA9", AT_FDCWD, "/media/vboxsf/.../Cargo.toml") = -1 ETXTBSY (Text file busy)
...
write(2, " Text file busy (os error 26)\n", 31) = 31
unlink("/media/vboxsf/.../Cargo.tomleN6hA9") = -1 ETXTBSY (Text file busy)
close(3) = 0
Notes
No response
Version
cargo 1.76.0 (c84b36747 2024-01-18)
release: 1.76.0
commit-hash: c84b367471a2db61d2c2c6aab605b14130b8a31b
commit-date: 2024-01-18
host: x86_64-unknown-linux-gnu
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Debian 12 (bookworm) [64-bit]