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

Fix: Don't parse the home directory more than once #3078

Merged
merged 4 commits into from
Sep 9, 2016
Merged

Fix: Don't parse the home directory more than once #3078

merged 4 commits into from
Sep 9, 2016

Conversation

jhbabon
Copy link
Contributor

@jhbabon jhbabon commented Sep 8, 2016

This PR tries to resolve this issue #3070. The problem is that the walk_tree method in the src/util/config.rs module was parsing more than once the contents of the config file in the home directory (the file ~/.cargo/config). The biggest problem with this is with options that can accept multiple values, like build.rustflags. If you parse the file twice, the same option can end with duplicated values (e.g: rustflags=["-Z", "foo", "-Z", "foo"]).

I made the fix following the comments in the issue. In the fix I keep track of all the parsed config files in a HashSet so I can know if a file has been parsed already. I'm also using std::fs::canonicalize, as suggested in the issue, to prevent parsing files behind symbolic links more than once.

UPDATE: I removed the call to fs::canonicalize as suggested in the comments. Now the fix is way simpler, which means less code and less possibilities to add a new bug.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.


impl ConfigFile {
pub fn new(path: PathBuf) -> ConfigFile {
let canonical = match fs::canonicalize(path) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this didn't previously call fs::canonicalize, so perhaps this could be left out?

Copy link
Contributor Author

@jhbabon jhbabon Sep 8, 2016

Choose a reason for hiding this comment

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

No, it's new, but It was suggested in the original issue (here #3070 (comment)) and I thought it was a good idea. I can remove it of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I'm thinking, if I remove the fs::canonicalize call I don't really need the struct. I put it only to simplify the "canonicalization" process. I think it would be simpler if I remove the struct and leave only the HashSet.

@alexcrichton
Copy link
Member

Thanks @jhbabon!

@jhbabon
Copy link
Contributor Author

jhbabon commented Sep 9, 2016

@alexcrichton any idea why the AppVeyor tests fail? I didn't touch those specs, I think.

* Remove ConfiFile struct, it is not needed without the fs::canonicalize
  call.
* Don't check if the file is in the stash when walking the tree,
  without "canonicalization" it is not necessary.
@jhbabon
Copy link
Contributor Author

jhbabon commented Sep 9, 2016

@alexcrichton I removed the call to fs::canonicalize and simplify the code. Now I'm only keeping track of the files walked during the initial loop and check if the home config file has been already parsed afterwards. I think its the simplest solution for this issue I can think off.

@alexcrichton
Copy link
Member

@bors: r+ 68d7823

Awesome, thanks!

@bors
Copy link
Collaborator

bors commented Sep 9, 2016

⌛ Testing commit 68d7823 with merge 398de25...

bors added a commit that referenced this pull request Sep 9, 2016
Fix: Don't parse the home directory more than once

This PR tries to resolve this issue #3070. The problem is that the `walk_tree` method in the `src/util/config.rs` module was parsing more than once the contents of the config file in the home directory (the file `~/.cargo/config`). The biggest problem with this is with options that can accept multiple values, like `build.rustflags`. If you parse the file twice, the same option can end with duplicated values (e.g: `rustflags=["-Z", "foo", "-Z", "foo"]`).

I made the fix following the comments in the issue. In the fix I keep track of all the parsed config files in a `HashSet` so I can know if a file has been parsed already. ~~I'm also using `std::fs::canonicalize`, as suggested in the issue, to prevent parsing files behind symbolic links more than once.~~

**UPDATE:** I removed the call to `fs::canonicalize` as suggested in the comments. Now the fix is way simpler, which means less code and less possibilities to add a new bug.
@bors
Copy link
Collaborator

bors commented Sep 9, 2016

💔 Test failed - cargo-win-gnu-32

@alexcrichton
Copy link
Member

@bors: retry

On Fri, Sep 9, 2016 at 9:29 AM, bors notifications@github.com wrote:

💔 Test failed - cargo-win-gnu-32
https://buildbot.rust-lang.org/builders/cargo-win-gnu-32/builds/698


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3078 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95CGHjvxxR-AcLkl_lR4cniGp2e6Oks5qoYl7gaJpZM4J4bce
.

@bors
Copy link
Collaborator

bors commented Sep 9, 2016

⚡ Previous build results for cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64 are reusable. Rebuilding only cargo-cross-linux, cargo-win-gnu-32...

@bors
Copy link
Collaborator

bors commented Sep 9, 2016

☀️ Test successful - cargo-cross-linux, cargo-linux-32, cargo-linux-64, cargo-mac-32, cargo-mac-64, cargo-win-gnu-32, cargo-win-gnu-64, cargo-win-msvc-32, cargo-win-msvc-64
Approved by: alexcrichton
Pushing 398de25 to master...

@bors bors merged commit 68d7823 into rust-lang:master Sep 9, 2016
@jhbabon jhbabon deleted the fix/parse-home-config-once branch September 9, 2016 17:45
@jhbabon
Copy link
Contributor Author

jhbabon commented Sep 9, 2016

Great! Thanks @alexcrichton !

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.

4 participants