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

Small fixes to setting Windows file permissions #31892

Closed
wants to merge 5 commits into from
Closed

Small fixes to setting Windows file permissions #31892

wants to merge 5 commits into from

Conversation

pitdicker
Copy link
Contributor

On Windows files can have a simple read-only permission flag, and the more complex access rights
and access control lists. The read-only flag is one bit of the file attributes.

To make sure only the read-only flag is toggled and not the other attributes, read the files
attributes and write them back with only this bit changed. By reading and setting the attributes
from the handle the file does not have to be opened twice.

Also directories can not be read-only, here the flag has a different meaning. So we should no
longer report directories as read-only, and also not allow making them read-only.

Note: This pr is split out from the one I am making for #29497. For that I need to be able to
remove the read-only flags from an already open handle. And the read-only detection needed to be
more robust.

On Windows files can have a simple read-only permission flag, and the
more complex access rights
and access control lists. The read-only flag is one bit of the file
attributes.

To make sure only the read-only flag is toggled and not the other
attributes, read the files
attributes and write them back with only this bit changed. By reading
and setting the attributes
from the handle the file does not have to be opened twice.

Also directories can not be read-only, here the flag has a different
meaning. So we should no
longer report directories as read-only, and also not allow making them
read-only.
@pitdicker
Copy link
Contributor Author

One more reason we might want this: currently set_permissions can be (ab)used to copy file attributes. I think it should just not touch them.

} else {
self.set_attributes(attr | c::FILE_ATTRIBUTE_READONLY)
},
(false, true) => self.set_attributes(attr & !c::FILE_ATTRIBUTE_READONLY),
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this branch also make sure that the file isn't a directory? Or actually, why not just always return an error if it is a directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, yes it should. Thank you!

@pitdicker
Copy link
Contributor Author

I chose to return Ok(()) if we try to remove the read-only flag from a directory.
This way recursively removing read-only permission is as simple on Windows as it is on Unix, no need to special-case directories.

I still feel a little sad that you can't simply do chmod -R a-x on Unix to remove execute permission from all files, but have to special-case directories.

@pitdicker
Copy link
Contributor Author

No high-five today?
r? @alexcrichton? I hope you don't mind

@pitdicker
Copy link
Contributor Author

I messed up git :(. this pr is now included in #31944. So closing this one

@pitdicker pitdicker closed this Feb 28, 2016
@pitdicker pitdicker deleted the readonly_perm branch February 22, 2019 19:48
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.

3 participants