Stebalien / tempfile

Temporary file library for rust
http://stebalien.com/projects/tempfile-rs
Apache License 2.0
1.2k stars 120 forks source link

Would `SetFileInformationByHandle` even be helpful for `persist`? #234

Closed LegionMammal978 closed 1 year ago

LegionMammal978 commented 1 year ago

In the persist() implementation for Windows, I noticed a comment:

// TODO: We should probably do this in one-shot using SetFileInformationByHandle but the API is
// really painful.

I was interested in seeing if I could work through the painful API and file a PR to implement this. However, SetFileInformationByHandle does not appear to allow moving a file and modifying its attributes at the same time. The FileAttributes are only contained in FILE_BASIC_INFO, the destination path is only contained in FILE_RENAME_INFO, and SetFileInformationByHandle only allows one of these to be passed at a time. So it would still end up taking 3 calls to SetFileInformationByHandle; the only benefit is that we could use the handle directly instead of going through the path. (NtSetInformationFile is more powerful, but it can still only change one of the FILE_BASIC_INFORMATION or FILE_RENAME_INFORMATION at a time.)

As far as I can tell, the closest thing to being able to perform both operations "in one-shot" would be to use the Transactional NTFS functions, which, as the name suggests, only work with NTFS.

Stebalien commented 1 year ago

I wrote that comment so long ago I can't even remember. But you're probably right. Want to submit a patch removing that comment?