Skip to content

rustc: Fix permission denied error in 'ar' when lto is enabled #17619

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

Merged
merged 1 commit into from
Sep 29, 2014

Conversation

wizeman
Copy link
Contributor

@wizeman wizeman commented Sep 29, 2014

The reason that 'ar' can fail with permission denied is that when
link-time optimizations are enabled, rustc copies libraries into a
temporary directory, preserving file permissions, and subsequently
modifies them using 'ar'.

The modification can fail because some package managers may install
libraries in system directories as read-only files, which means the
temporary file also becomes read-only when it is copied.

I have fixed this by giving the temporary file's owner read+write
permissions after the copy.

I have also added a regression test for this issue.

@rust-highfive
Copy link
Contributor

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

match fs::chmod(&dst, io::UserRead | io::UserWrite) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to chmod {}: {}",
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could include some more information, e.g. why the chmod is necessary, and, if possible, what the user can do to fix it? (As a user, I would find it unintuitive that the compiler is trying to chmod a copy of some external crate; specifically mentioning LTO would be a good start, e.g. "failed to chmod {} when preparing for LTO: {}".)

@huonw
Copy link
Member

huonw commented Sep 29, 2014

Looks good, thanks! Just a few little nits and I think this will be ready to meet our integration bot.

The reason that 'ar' can fail with permission denied is that when
link-time optimizations are enabled, rustc copies libraries into a
temporary directory, preserving file permissions, and subsequently
modifies them using 'ar'.

The modification can fail because some package managers may install
libraries in system directories as read-only files, which means the
temporary file also becomes read-only when it is copied.

I have fixed this by giving the temporary file's owner read+write
permissions after the copy.

I have also added a regression test for this issue.
@wizeman
Copy link
Contributor Author

wizeman commented Sep 29, 2014

@huonw Thanks for the review!

I have made the changes you mentioned.
I have also rebased and fixed a small problem, where the error message was displaying the path of the original file, instead of the temporary copy (which is the one where the chmod would be failing).

If you would like me to change anything else, please let me know.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 29, 2014
@bors bors merged commit 991f506 into rust-lang:master Sep 29, 2014
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.

5 participants