Shinmera / file-attributes

Access to common file attributes (uid, gid, permissions, ctime, mtime, atime)
https://shinmera.github.io/file-attributes
zlib License
17 stars 2 forks source link

Read/write of times for directories fails to `CreateFile` on Windows #5

Closed jaredkrinke closed 10 months ago

jaredkrinke commented 10 months ago

Is the intention of this library to support reading directory times as well? If so, then this seems like a bug in the Windows implementation.

Potential solution

According to https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#directories

To open a directory using CreateFile, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFlagsAndAttributes. Appropriate security checks still apply when this flag is used without SE_BACKUP_NAME and SE_RESTORE_NAME privileges.

If I add that flag, then I'm able to get/set the modification time for a directory on my NTFS drive on Windows 10. I haven't tested FAT. I'm using this change successfully and the commit is here:

https://github.com/Shinmera/file-attributes/compare/master...jaredkrinke:file-attributes:master

If you think this is a valid scenario/bug and you want me to open a PR, let me know. No worries if you'd rather solve it a different way/yourself!

Thanks for creating this library (and many others)!

Shinmera commented 10 months ago

your solution seems fine, please submit a PR.