2 ms·
Wouldn't a perfect solution be to add a function "queue file deletion after it is closed" to Windows?
by codedokode 4y ago
Wouldn't a perfect solution be to add a function "queue file deletion after it is closed" to Windows?
- 323 4y agoIt already has something similar, you can request for the deletion of a locked file on reboot.
- codedokode 4y agoNo that's not what I meant. I meant delete at the moment file becomes unused.
- smileybarry 4y agoIt's supported if the current program allows it. "FILE_SHARE_DELETE" means your delete succeeds but gets processed once their handle closes.
- codedokode 4y agoThis doesn't make much sense though. Why do we need a program's permission to delete file after it has been closed?
- smileybarry 4y agoIt’s not after it’s been closed, it’s during. When you open a file on Windows, you can share: read, write and/or “mark to delete”. A lot of times you don’t share any (read can lead to data incoherency; write means you can go out of sync in offsets with someone else; delete might not be relevant if it’s your database file). But if you do, the file isn’t “locked” if someone else opens it for the permissions you’ve agreed to share. “FILE_SHARE_DELETE” is a little tricky because you can’t delete a file in use, because after all it’s _in use_. So instead, your request to delete puts a mark on it that prevents future opens, and completes the delete once the previously open handles all close. And except for very specific cases (PE mapping, special “on-purpose” locking, specific APIs) you can always rename/move a file in use, so combined with “FILE_SHARE_DELETE” it’s sort of equivalent except for the space not being freed immediately.