Skip to content

HTML renderer doesn't handle windows symlinks #1209

@Michael-F-Bryan

Description

@Michael-F-Bryan

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions