Doc lock file not getting deleted after successful docs generation, causing permission error

In my CI/CD pipeline, I generate docs with cargo doc --workspace --no-deps --document-private-items. This generates a lock file at target/doc/.lock. Now for some reason, this lock file doesn't get removed when cargo is done with generating the documentation, even when it exits with exit code 0.

In this case, my CI job uploads the entire target/docs directory as a CI artifact. But when I download these files again, copying them falls due to missing permissions on the lock file

$ cp -fr target/doc public/code-doc
cp: can't open 'target/doc/.lock': Permission denied

There seems to be some precedence on this issue, for example here and here where the workaround seems to je to delete the lock file. But I haven't been able to find a concrete post about fixing this issue, which is why I'm posting here.

Has anyone else encountered this issue? I unfortunately have been unable to reliably recreate it.

The .lock file is indeed never removed. This is expected. It is not the presence of the .lock file that locks the directory, rather an advisory file lock is taken on the .lock file. This way crashing cargo doesn't leave the directory locked.

Can you check what the file permissions of the .lock file are?

The lock file has -rw------- permissions, while every other file in target/doc has -rw-r--r-- permissions. The directories all have drwxr-xr-x permissions.

I suspect I can't remove the lock file because the later stages use a new Docker container with a new user, which doesn't map up with the user that generated the documentation and thus the lock file?