You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In one of my books, I'd like to distribute a copy of a PDF. To make sure the document in my book doesn't get out of sync with the original I'm using a symlink.
I'm on a windows computer, so I created the symlink with the following:
Now when I run the build server mdbook serve --open go to http://localhost:3000/overview.html, and click the link to some-document.pdf it will serve up a zero byte file... Which is kinda not helpful.
I believe what's happened is the HTML renderer copied the symlink as-is, meaning the output directory now contains a broken symlink. Because the output directory is meant to be copied around and standalone, we should be copying the actual file contents to the output directory.
One solution would be for the HTML renderer to run std::fs::canonicalize() first when copying files across (e.g. to resolve any symlinks), probably in mdbook::utils::copy_files_except_ext(). I'm not sure how much code depends on this function though.
The text was updated successfully, but these errors were encountered:
It doesn't look like this is specific to Windows, is it? Symbolic links don't seem to work on unix, either. I think it might be something as simple as:
diff --git a/src/utils/fs.rs b/src/utils/fs.rs
index 570e84282..56740e479 100644
--- a/src/utils/fs.rs+++ b/src/utils/fs.rs@@ -113,7 +113,7 @@ pub fn copy_files_except_ext(
for entry in fs::read_dir(from)? {
let entry = entry?;
- let metadata = entry.metadata()?;+ let metadata = entry.path().metadata()?;
// If the entry is a dir and the recursive option is enabled, call itself
if metadata.is_dir() && recursive {
In one of my books, I'd like to distribute a copy of a PDF. To make sure the document in my book doesn't get out of sync with the original I'm using a symlink.
I'm on a windows computer, so I created the symlink with the following:
$ mklink "../../../Install Files/Documentation/some-document.pdf" "some-document.pdf"
My directory structure looks something like this:
docs/
book.toml
src/
SUMMARY.md
overview.md
some-document.pdf
->../../../Install Files/Documentation/some-document.pdf
Now when I run the build server
mdbook serve --open
go tohttp://localhost:3000/overview.html
, and click the link tosome-document.pdf
it will serve up a zero byte file... Which is kinda not helpful.I believe what's happened is the HTML renderer copied the symlink as-is, meaning the output directory now contains a broken symlink. Because the output directory is meant to be copied around and standalone, we should be copying the actual file contents to the output directory.
One solution would be for the HTML renderer to run
std::fs::canonicalize()
first when copying files across (e.g. to resolve any symlinks), probably inmdbook::utils::copy_files_except_ext()
. I'm not sure how much code depends on this function though.The text was updated successfully, but these errors were encountered: