-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add a method for setting permissions directly on an open file. #37886
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Just set the file times to 0. That way they won't update and you'll only modify the file attributes. |
Is that documented anywhere? I couldn't find that information on MSDN. |
I couldn't find any documentation about it myself, but I'm pretty sure it is a feature. Even |
Grumble... undocumented APIs... anti-trust settlement... sigh (but thanks). |
@@ -417,6 +417,24 @@ impl File { | |||
Ok(PathBuf::from(OsString::from_wide(subst))) | |||
} | |||
} | |||
|
|||
pub fn set_permissions(&self, perm: FilePermissions) -> io::Result<()> { | |||
let mut info = c::FILE_END_OF_FILE_INFO { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong struct name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
let mut info = c::FILE_END_OF_FILE_INFO { | ||
CreationTime: 0, | ||
LastAccessTime: 0, | ||
LastWriteTime: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field isn't listed in your FILE_BASIC_INFO
definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
2f404f5
to
1ebe3ef
Compare
So, the question is, does this need an RFC (it's a new public API but it mirrors methods like |
This is small enough that it shouldn't need an RFC, although it might still go through the rfcbot merge process with the libs subteam. |
Looks good to me, thanks @Stebalien! Yeah it's ok to not have an RFC for this. Could you file a tracking issue for this, though, and fill that out? I'll tag it afterwards and then r+ so we can land. |
Done. |
/// prefer [`File::set_permissions`]. | ||
/// | ||
/// [`File`]: struct.File.html | ||
/// [`File::set_permissions`]: struct.File.html#method.set_permissions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before you merge, would you like me to keep this note or wait till File::set_permissions
stabilizes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah let's leave this out until the method stabilizes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@bors: r+ |
📌 Commit 11e8120 has been approved by |
Add a method for setting permissions directly on an open file. On unix like systems, the underlying file corresponding to any given path may change at any time. This function makes it possible to set the permissions of the a file corresponding to a `File` object even if its path changes. @retep998, what's the best way to do this on Windows? I looked into `SetFileInformationByHandle` but couldn't find a way to do it atomically risking clobbering access time information. This is a first step towards fixing #37885. This function doesn't *have* to be public but this is useful functionality that should probably be exposed.
💔 Test failed - auto-win-msvc-64-opt-rustbuild |
On unix like systems, the underlying file corresponding to any given path may change at any time. This function makes it possible to set the permissions of the a file corresponding to a `File` object even if its path changes.
(should be fixed, sorry). |
@bors: r+ |
📌 Commit 1aaca5f has been approved by |
⌛ Testing commit 1aaca5f with merge ccdc26f... |
Add a method for setting permissions directly on an open file. On unix like systems, the underlying file corresponding to any given path may change at any time. This function makes it possible to set the permissions of the a file corresponding to a `File` object even if its path changes. @retep998, what's the best way to do this on Windows? I looked into `SetFileInformationByHandle` but couldn't find a way to do it atomically risking clobbering access time information. This is a first step towards fixing #37885. This function doesn't *have* to be public but this is useful functionality that should probably be exposed.
On unix like systems, the underlying file corresponding to any given path may change at any time. This function makes it possible to set the permissions of the a file corresponding to a
File
object even if its path changes.@retep998, what's the best way to do this on Windows? I looked into
SetFileInformationByHandle
but couldn't find a way to do it atomically risking clobbering access time information.This is a first step towards fixing #37885. This function doesn't have to be public but this is useful functionality that should probably be exposed.