mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Files copied to output directory with readonly attribute cause subsequent build/serve failure

Open snalexp opened this issue 6 years ago • 1 comments

We store our book source in Perforce which typically causes files on the local drive to be read-only.

When we mdbook build, our images from the src/image directory end up marked as read-only in the book/img directory and subsequent builds will fail like this:

..\build\bin\mdbook.exe build
2019-08-21 08:05:41 [INFO] (mdbook::book): Book building has started
2019-08-21 08:05:41 [ERROR] (mdbook::utils): Error: Unable to clear output directory
2019-08-21 08:05:41 [ERROR] (mdbook::utils):    Caused By: Access is denied. (os error 5)

Would it be possible to copy the files and drop the RO attribute, or to be more forceful in cleaning the output directory.

The following steps should reproduce on Windows:

> mdbook init
Do you want a .gitignore to be created? (y/n)
n
What title would you like to give the book?
test

> mkdir src\img
> echo dummy > src\img\test.png
> attrib +R src\img\test.png
> mdbook build   <-- Success when book dir doesn't exist
> mdbook build   <-- Failure when book dir contains RO file

snalexp avatar Aug 21 '19 07:08 snalexp

This also breaks building mdbook books under Nix (https://nixos.org/). With Nix, the source tree is read-only. For some reason, additional-css files are copied twice (probably https://github.com/rust-lang/mdBook/issues/1156), and the second copy fails with EACCESS because the first copy also set the access mode of the destination file to read-only.

openat(AT_FDCWD, "/nix/store/2i4mc95ndwgww8mpv0gj19hqnbynz9cb-crane-book/custom.css", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0100444) = 4
...
openat(AT_FDCWD, "/nix/store/2i4mc95ndwgww8mpv0gj19hqnbynz9cb-crane-book/custom.css", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0100444) = -1 EACCES (Permission denied)

(/nix/store/2i4mc95ndwgww8mpv0gj19hqnbynz9cb-crane-book is the destination path for the build, here)

tv42 avatar Feb 23 '25 04:02 tv42