Cargo: Cargo cannot update crates.io index on NFS

Created on 11 Feb 2019  路  6Comments  路  Source: rust-lang/cargo

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

  1. CARGO_HOME=/path/to/nfs/.cargo cargo install rg, probably any package will cause this error

Notes

  • cargo 1.31.0 (339d9f9c8 2018-11-16)
  • Ubuntu 18.04
A-filesystem C-bug

Most helpful comment

I have found a workaround for this issue:

Adding,

[net]
git-fetch-with-cli = true

to .cargo/config fixes the issue

All 6 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodoufu picture rodoufu  路  3Comments

disconsented picture disconsented  路  3Comments

alilleybrinker picture alilleybrinker  路  3Comments

ehuss picture ehuss  路  3Comments

japaric picture japaric  路  3Comments