Cygwin: improve O_TMPFILE handling

Windows does not remove FILE_ATTRIBUTE_TEMPORARY by itself after a
file has been closed.  It's just some attribute which can be set or
removed at will, despite its purpose.

Apparently there are tools out there which use FILE_ATTRIBUTE_TEMPORARY
accidentally or wrongly, even Microsoft's own tools are affected.  In
the end, the filesystem is potentially full of files with this attribute
set.

Implement O_TMPFILE files with FILE_ATTRIBUTE_TEMPORARY and
FILE_ATTRIBUTE_HIDDEN set.  This combination is pretty unlikely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2018-02-14 12:55:24 +01:00
parent 1188d308bf
commit 7ae73be141
3 changed files with 28 additions and 12 deletions

View File

@@ -603,11 +603,14 @@ fhandler_base::open (int flags, mode_t mode)
as with FILE_ATTRIBUTE_TEMPORARY. The latter speeds up file access,
because the OS tries to keep the file in memory as much as possible.
In conjunction with FILE_DELETE_ON_CLOSE, ideally the OS never has
to write to the disk at all. */
to write to the disk at all.
Note that O_TMPFILE_FILE_ATTRS also sets the DOS HIDDEN attribute
to help telling Cygwin O_TMPFILE files apart from other files
accidentally setting FILE_ATTRIBUTE_TEMPORARY. */
if (flags & O_TMPFILE)
{
access |= DELETE;
file_attributes |= FILE_ATTRIBUTE_TEMPORARY;
file_attributes |= O_TMPFILE_FILE_ATTRS;
options |= FILE_DELETE_ON_CLOSE;
}