Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a possible recursive copy when destination (build_dir) is underneath source directory #1026

Merged
merged 2 commits into from
Apr 3, 2020

Conversation

andrewdavidmackenzie
Copy link
Contributor

If the user makes a mistake in config mdbook could have started a never-ending copy that only ends when your disk is full. This change avoids that.

It also makes it possible to create a valid (if not recommended) configuration where your build-dir is underneath the src directory. One reason for possibly wishing to do that is when you desire src to be the root directory of a project.

Relates to #1024

@andrewdavidmackenzie
Copy link
Contributor Author

Any feedback on this PR?

@ehuss
Copy link
Contributor

ehuss commented Oct 5, 2019

I'm having trouble figuring out the configuration where this is a problem. If I set build.build-dir to src/foo, I don't see any problems happening. What is a configuration where it causes recursion?

@andrewdavidmackenzie
Copy link
Contributor Author

When you have the book.toml file in the root of your project.

in book.toml you have src = "."

and the build dir is also under the root somewhere, something like

[build]
build-dir = "target"

So, during the build all the contents of "src" (so all files - except filtered .md files) are copied into "target", including "target" itself - recursing.

in short: when "build-dir" is a subdir of "src".

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have the book.toml file in the root of your project.

Ah. I still can't reproduce it, but I suspect it depends on how the OS handles mutating the directory while iterating over it. Seems reasonable to try to guard against it, though.

src/utils/fs.rs Outdated Show resolved Hide resolved
src/utils/fs.rs Show resolved Hide resolved
book-example/src/cli/build.md Outdated Show resolved Hide resolved
@andrewdavidmackenzie
Copy link
Contributor Author

OK, I hope that addresses the two comments on texts in the PR.

@ehuss ehuss merged commit 769cc0a into rust-lang:master Apr 3, 2020
@andrewdavidmackenzie
Copy link
Contributor Author

andrewdavidmackenzie commented Apr 3, 2020

Thanks. I'll switch to release v0.3.7 now!

Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Avoid a possible recursive copy when destination (build_dir) is underneath source directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants