-
Notifications
You must be signed in to change notification settings - Fork 13k
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
feat: add tier-1 platform support for change_time #128256
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,7 +298,7 @@ impl OpenOptionsExt for OpenOptions { | |
/// of the [`BY_HANDLE_FILE_INFORMATION`] structure. | ||
/// | ||
/// [`BY_HANDLE_FILE_INFORMATION`]: | ||
/// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information | ||
/// https://docs.microsoft.com/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
pub trait MetadataExt { | ||
/// Returns the value of the `dwFileAttributes` field of this metadata. | ||
|
@@ -322,7 +322,7 @@ pub trait MetadataExt { | |
/// ``` | ||
/// | ||
/// [File Attribute Constants]: | ||
/// https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants | ||
/// https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
fn file_attributes(&self) -> u32; | ||
|
||
|
@@ -351,7 +351,7 @@ pub trait MetadataExt { | |
/// } | ||
/// ``` | ||
/// | ||
/// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
/// [`FILETIME`]: https://docs.microsoft.com/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
fn creation_time(&self) -> u64; | ||
|
||
|
@@ -386,7 +386,7 @@ pub trait MetadataExt { | |
/// } | ||
/// ``` | ||
/// | ||
/// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
/// [`FILETIME`]: https://docs.microsoft.com/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
fn last_access_time(&self) -> u64; | ||
|
||
|
@@ -419,7 +419,7 @@ pub trait MetadataExt { | |
/// } | ||
/// ``` | ||
/// | ||
/// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
/// [`FILETIME`]: https://docs.microsoft.com/windows/win32/api/minwinbase/ns-minwinbase-filetime | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
fn last_write_time(&self) -> u64; | ||
|
||
|
@@ -471,10 +471,21 @@ pub trait MetadataExt { | |
#[unstable(feature = "windows_by_handle", issue = "63010")] | ||
fn file_index(&self) -> Option<u64>; | ||
|
||
/// Returns the change time, which is the last time file metadata was changed, such as | ||
/// renames, attributes, etc | ||
/// | ||
/// This will return `None` if the `Metadata` instance was not created using the `FILE_BASIC_INFO` type. | ||
/// Returns the value of the `ChangeTime{Low,High}` field from the | ||
/// [`FILE_BASIC_INFO`] struct associated with the current file handle. | ||
/// [`ChangeTime`], is the last time file metadata was changed, such as | ||
/// renames, attributes, etc. | ||
/// | ||
/// This will return `None` if `Metadata` was populated without access to | ||
/// [`FILE_BASIC_INFO`]. For example, the result of `std::fs::read_dir` | ||
/// will be derived from [`WIN32_FIND_DATA`] which does not have access to | ||
/// `ChangeTime`. | ||
/// | ||
/// [`FILE_BASIC_INFO`]: https://learn.microsoft.com/windows/win32/api/winbase/ns-winbase-file_basic_info | ||
/// [`WIN32_FIND_DATA`]: https://learn.microsoft.com/windows/win32/api/minwinbase/ns-minwinbase-win32_find_dataw | ||
/// [`FindFirstFile`]: https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-findfirstfilea | ||
/// [`FindNextFile`]: https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-findnextfilea | ||
/// [`ChangeTime`]: https://devblogs.microsoft.com/oldnewthing/20100709-00/?p=13463#:~:text=I%E2%80%99m%20told%20that%20the%20difference%20is%20metadata.%20The,attributes%20%28hidden%2C%20read-only%2C%20etc.%29%20or%20renaming%20the%20file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this has some highlighting, https://devblogs.microsoft.com/oldnewthing/20100709-00/?p=13463 seems to work |
||
#[unstable(feature = "windows_change_time", issue = "121478")] | ||
fn change_time(&self) -> Option<u64>; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,12 +371,19 @@ impl File { | |
reparse_tag = attr_tag.ReparseTag; | ||
} | ||
} | ||
|
||
// FILE_BASIC_INFO contains additional fields not returned by GetFileInformationByHandle | ||
let basic_info = self.basic_info()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what the failure conditions are here, is accessing If failures are possible, you can just do |
||
|
||
Ok(FileAttr { | ||
attributes: info.dwFileAttributes, | ||
creation_time: info.ftCreationTime, | ||
last_access_time: info.ftLastAccessTime, | ||
last_write_time: info.ftLastWriteTime, | ||
change_time: None, // Only available in FILE_BASIC_INFO | ||
change_time: Some(c::FILETIME { | ||
dwLowDateTime: basic_info.ChangeTime as u32, | ||
dwHighDateTime: (basic_info.ChangeTime >> 32) as u32, | ||
}), | ||
file_size: (info.nFileSizeLow as u64) | ((info.nFileSizeHigh as u64) << 32), | ||
reparse_tag, | ||
volume_serial_number: Some(info.dwVolumeSerialNumber), | ||
|
@@ -391,14 +398,7 @@ impl File { | |
#[cfg(target_vendor = "uwp")] | ||
pub fn file_attr(&self) -> io::Result<FileAttr> { | ||
unsafe { | ||
let mut info: c::FILE_BASIC_INFO = mem::zeroed(); | ||
let size = mem::size_of_val(&info); | ||
cvt(c::GetFileInformationByHandleEx( | ||
self.handle.as_raw_handle(), | ||
c::FileBasicInfo, | ||
core::ptr::addr_of_mut!(info) as *mut c_void, | ||
size as u32, | ||
))?; | ||
let mut info: c::FILE_BASIC_INFO = self.basic_info()?; | ||
let mut attr = FileAttr { | ||
attributes: info.FileAttributes, | ||
creation_time: c::FILETIME { | ||
|
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.
Spurious comma