Skip to content

Commit e844038

Browse files
committed
Feat. adding ext that returns change_time
1 parent 408bbd0 commit e844038

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

library/std/src/os/windows/fs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ pub trait MetadataExt {
471471
/// `fs::metadata` or `File::metadata`, then this will return `Some`.
472472
#[unstable(feature = "windows_by_handle", issue = "63010")]
473473
fn file_index(&self) -> Option<u64>;
474+
475+
476+
/// Returns the change time, which is the last time file metadata was changed, such as
477+
/// renames, attributes, etc.
478+
///
479+
/// This will return `None` if the `Metdata` instance was not created using the FILE_BASIC_INFO type,
480+
// #[stable(feature = "metadata_ext", since = "1.1.0")] not sure what to do here
481+
fn change_time(&self) -> Option<u64>;
474482
}
475483

476484
#[stable(feature = "metadata_ext", since = "1.1.0")]
@@ -499,6 +507,9 @@ impl MetadataExt for Metadata {
499507
fn file_index(&self) -> Option<u64> {
500508
self.as_inner().file_index()
501509
}
510+
fn change_time(&self) -> Option<u64> {
511+
self.as_inner().change_time()
512+
}
502513
}
503514

504515
/// Windows-specific extensions to [`fs::FileType`].

library/std/src/sys/windows/fs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct FileAttr {
2929
creation_time: c::FILETIME,
3030
last_access_time: c::FILETIME,
3131
last_write_time: c::FILETIME,
32+
change_time: Option<c::FILETIME>,
3233
file_size: u64,
3334
reparse_tag: c::DWORD,
3435
volume_serial_number: Option<u32>,
@@ -352,6 +353,7 @@ impl File {
352353
creation_time: info.ftCreationTime,
353354
last_access_time: info.ftLastAccessTime,
354355
last_write_time: info.ftLastWriteTime,
356+
change_time: None, // Only available in FILE_BASIC_INFO
355357
file_size: (info.nFileSizeLow as u64) | ((info.nFileSizeHigh as u64) << 32),
356358
reparse_tag,
357359
volume_serial_number: Some(info.dwVolumeSerialNumber),
@@ -388,6 +390,10 @@ impl File {
388390
dwLowDateTime: info.LastWriteTime as c::DWORD,
389391
dwHighDateTime: (info.LastWriteTime >> 32) as c::DWORD,
390392
},
393+
change_time: Some(c::FILETIME {
394+
dhLowDateTime: info.ChangeTime as c::DWORD,
395+
dhHighDateTime: (info.ChangeTime >> 32) as c::DWORD,
396+
}),
391397
file_size: 0,
392398
reparse_tag: 0,
393399
volume_serial_number: None,
@@ -956,6 +962,10 @@ impl FileAttr {
956962
to_u64(&self.creation_time)
957963
}
958964

965+
pub fn changed_u64(&self) -> Option<u64> {
966+
self.changed_time.map(|c| to_u64(c))
967+
}
968+
959969
pub fn volume_serial_number(&self) -> Option<u32> {
960970
self.volume_serial_number
961971
}
@@ -975,6 +985,7 @@ impl From<c::WIN32_FIND_DATAW> for FileAttr {
975985
creation_time: wfd.ftCreationTime,
976986
last_access_time: wfd.ftLastAccessTime,
977987
last_write_time: wfd.ftLastWriteTime,
988+
change_time: None,
978989
file_size: ((wfd.nFileSizeHigh as u64) << 32) | (wfd.nFileSizeLow as u64),
979990
reparse_tag: if wfd.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
980991
// reserved unless this is a reparse point

0 commit comments

Comments
 (0)