rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.57k stars 12.74k forks source link

Tracking Issue for `windows_change_time` #121478

Open juliusl opened 8 months ago

juliusl commented 8 months ago

In Windows, there's a field in FILE_BASIC_INFO called ChangeTime that tracks when file metadata is changed, such as renaming, file attributes, etc.

Currently, this property isn't included in the ::sys::windows::fs::FileAttr implementation, but is available in the c::FILE_BASIC_INFO impl.

Last write time (which is currently provided) is the last time the data stream changed, and this value represents a different time value.

source

This change adds a method change_time() to the MetadataExt trait in order to provide this value.

Public API

fn windows_change_time() {
    let meta = std::fs::metadata("example.txt").unwrap();

    // Returns Option<u64> since this is only available if FILE_BASIC_INFO is the backing type of `.inner()`
    let change_time = meta.change_time();
}

Steps / History

Unresolved Questions

tgross35 commented 3 months ago

The docs currently say:

This will return None if the Metadata instance was not created using the FILE_BASIC_INFO type.

Could you reword this to clarify what is required for somebody using Rust's APIs? It isn't clear how somebody may or may not wind up with a FILE_BASIC_INFO, since that type isn't mentioned anywhere.

juliusl commented 3 months ago

@tgross35 FILE_BASIC_INFO is a windows api struct and actually seeing the alternative implementation I think we could align both implementations so that I can return a value in both cases, see -- https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex#remarks

I'll tinker and see if I can draft something

tgross35 commented 3 months ago

@tgross35 FILE_BASIC_INFO is a windows api struct

As in, to non-uwp users this only comes up if they are using the windows crate? If that is accurate then it would just be good to mention, I just couldn't figure out how this gets used. But...

and actually seeing the alternative implementation I think we could align both implementations so that I can return a value in both cases, see -- https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex#remarks

I'll tinker and see if I can draft something

that sounds even better, cool.