I cannot use Cargo when my home directory is located on a networked file system (NFS)
Here is the error I get:
$ cargo install rg
Updating crates.io index
warning: spurious network error (2 tries remaining): failed to truncate pack file '/private/home/misterabc/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_RVSwU3': Permission denied; class=Os (2)
warning: spurious network error (1 tries remaining): failed to truncate pack file '/private/home/misterabc/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_iAwQaT': Permission denied; class=Os (2)
error: failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to truncate pack file '/private/home/misterabc/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/objects/pack/pack_git2_PMGzWR': Permission denied; class=Os (2)
Instead, if I do CARGO_HOME=/tmp/.cargo cargo install rg, everything seems to work out fine.
Steps
CARGO_HOME=/path/to/nfs/.cargo cargo install rg, probably any package will cause this errorNotes
Thanks for the report! This looks like it's likely coming from libgit2 so it may not be trivial to fix. What's probably happening is that some syscall libgit2 is expecting to work doesn't work on NFS. Can you try running strace to figure out what the failing syscall is? It'd also be great to get the stack trace at the time of failure of that syscall.
Here's the strace: https://gist.github.com/ebetica/1b77fdf65432ae894fc758a7e9ca1f43
I'm not sure how to get the stack trace. I think the problem is in ftruncate, no? It appears to me that the git pack files are created with only read permissions, where ftruncate expect it to be opened with write permissions?
Ah ok! Looks like this may be the same as https://github.com/rust-lang/cargo/issues/1578? I thought there was a flag for strace to print stacks but I may also be remembering incorrectly...
I have found a workaround for this issue:
Adding,
[net]
git-fetch-with-cli = true
to .cargo/config fixes the issue
Have run into the same issue with a rust corssbuild docker container on a windows machine, which earlier worked fine. FWIW, I use the default --mount flag to mount the cache folder:
Building aarch64 with cargo build --release --target aarch64-unknown-linux-gnu --verbose
Updating git repository `https://github.com/ashthespy/librespot`
warning: spurious network error (2 tries remaining): failed to truncate pack file '/build/cache/git/db/librespot-6f197fd632ef9380/objects/pack/pack_git2_wCQpdD': Operation not permitted; class=Os (2)
warning: spurious network error (1 tries remaining): failed to truncate pack file '/build/cache/git/db/librespot-6f197fd632ef9380/objects/pack/pack_git2_yWscE9': Operation not permitted; class=Os (2)
error: failed to load source for a dependency on `librespot`
Caused by:
Unable to update https://github.com/ashthespy/librespot?branch=vollibrespot#46749460
Caused by:
failed to fetch into /build/cache/git/db/librespot-6f197fd632ef9380
Caused by:
failed to truncate pack file '/build/cache/git/db/librespot-6f197fd632ef9380/objects/pack/pack_git2_ztnTVN': Operation not permitted; class=Os (2)
File permissions
root@56957e7897a3:/src# ls -la /build/cache/git/
total 0
drwxrwxrwx 1 root root 0 Mar 13 23:49 .
drwxrwxrwx 1 root root 0 Mar 13 23:49 ..
drwxrwxrwx 1 root root 0 Mar 13 23:49 checkouts
drwxrwxrwx 1 root root 0 Mar 14 00:17 db
The workaround from @felipellrocha seems to work inside the container, but any pointers on how to debug this?
Most helpful comment
I have found a workaround for this issue:
Adding,
to
.cargo/configfixes the issue