Strange 'cargo build' file permission warnings

Recently I started seeing 'cargo build' and the like compile OK but issue warnings like the following:

$ cargo build
...
warning: Error finalizing incremental compilation session directory `/mnt/c/Users/zicog/conq-ws/target/debug/incremental/conq_ws_server-2q1bffu1vnc1a/s-fq0xl8u26v-4gktak-working`: Permission denied (os error 13)

warning: 2 warnings emitted

warning: Error finalizing incremental compilation session directory `/mnt/c/Users/zicog/conq-ws/target/debug/incremental/conq_ws_client_cli-nqj4wzo9q5jf/s-fq0xl8tdgv-vzck31-working`: Permission denied (os error 13)

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
$

Getting 'permission denied' seems odd as I have pretty liberal permissions on everything here:

$ ls -l /mnt/c/Users/conq-ws/target/debug/
total 175840
drwxrwxrwx 1 zicog zicog      512 Aug  7 20:26 build
-rwxrwxrwx 2 zicog zicog 52851648 Aug  7 20:28 conq-ws
-rwxrwxrwx 2 zicog zicog 46745984 Aug  7 20:28 conq_ws_client_cli
-rw-rw-rw- 1 zicog zicog      146 Aug  7 20:28 conq_ws_client_cli.d
-rw-rw-rw- 1 zicog zicog      117 Aug  7 20:28 conq-ws.d
-rwxrwxrwx 2 zicog zicog 70075864 Aug  7 20:28 conq_ws_server
-rw-rw-rw- 1 zicog zicog      138 Aug  7 20:28 conq_ws_server.d
drwxrwxrwx 1 zicog zicog      512 Aug  7 20:28 deps
drwxrwxrwx 1 zicog zicog      512 Aug  7 20:26 examples
drwxrwxrwx 1 zicog zicog      512 Aug  7 20:28 incremental
$ ls -l /mnt/c/Users/conq-ws/target
total 0
-rw-rw-rw- 1 zicog zicog 176 Aug  7 18:55 CACHEDIR.TAG
drwxrwxrwx 1 zicog zicog 512 Aug  7 20:28 debug
drwxrwxrwx 1 zicog zicog 512 Aug  7 18:58 release
$ ls -l /mnt/c/Users/conq-ws/
total 56
-rw-rw-rw- 1 zicog zicog 50356 Aug  7 18:50 Cargo.lock
-rw-rw-rw- 1 zicog zicog   751 Aug  7 18:50 Cargo.toml
drwxrwxrwx 1 zicog zicog   512 Aug  4 23:16 src
drwxrwxrwx 1 zicog zicog   512 Aug  7 20:26 target

Now, all this is happening on Debian inside the WSL on Win 10. I'm a newbie to Windows so perhaps there is something outside that I am not aware of.

Any ideas?

I get those kinds of errors sometimes and I don't do WSL. Windows is sometimes just finicky with rust compilation. When that happens what I do is rm -Recurse -Force ./target in PowerShell to deal with it.

In the case that cleaning out your compilation isn't worth it time-wise, you could always try to delete that specific file with admin privileges.

There seem to be some weird interaction between MS VS Code and cargo.

When VS Code is not running all is well. When it is running I see all kind of errors:

$ code .
$ cargo build
    Blocking waiting for file lock on build directory

$ cargo build
error: Permission denied (os error 13)

$ cargo build
warning: Error finalizing incremental compilation session directory `/mnt/c/Users/conq-ws/target/debug/incremental/conq_ws_client_cli-nqj4wzo9q5jf/s-fq0ysrmhya-16dp2yu-working`: Permission denied (os error 13)

VS Code seems to be holding something open I would rather it did not.

You could be running into path locks. This information may be grossly out of date, but if VSCode has a file open (even read-only), then any parent directory of that file will not be able to be renamed.

"finalizing incremental compilation session directory" seems like it could be attempting to make use of atomic rename as a transaction to commit results.

NB: I have no idea how any of this code actually works, so could be off base. :slight_smile:

I think, possibly, maybe, I found the solution.

VS Code has settings where you can configure match patterns to tell it to not include certain files and/or directories for searching, watching, etc.

I went into File -> Preferences -> Setting. In there I find Text editor -> Files. In there I find some places to add match patterns for Files: Exclude , Files Watcher: Exclude and Search: Exclude,

I add the pattern **/target/** to all of those.

And restart VS code.

As far as I can tell so far that has fixed the issue with those warnings.

Another hour wasted. Don't you love computers! :slight_smile:

Well, almost.

I just got:

$ cargo build
    Blocking waiting for file lock on build directory

a few times.

Which as far as I can tell from watching things is caused because VS Code is busy running rust-analyzer and or 'cargo check' itself at the time. Which can take a long while...

I guess there is not much to do about that.

But those warnings of my OP have gone.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.