attempt to reset create on Windows

When writing a file on Windows, you need to set the create date or the
date might be copied over from a previous file of the same name.

Quick hack, might be enough to fix this.

See https://github.com/jcupitt/libvips/issues/729
This commit is contained in:
John Cupitt 2017-09-07 09:09:19 +01:00
parent 739389d18d
commit 0911b4a282

View File

@ -543,6 +543,29 @@ vips__write( int fd, const void *buf, size_t count )
return( 0 ); return( 0 );
} }
#ifdef OS_WIN32
/* Deletes and resets the create date on the named file. This is necessary on
* Windows, or the create date may be copied over from an existing file of the
* same name.
*
* See https://blogs.msdn.microsoft.com/oldnewthing/20050715-14/?p=34923
*/
int
vips__delete_create( const char *path16 )
{
HANDLE handle;
/* Even though we're only writing, ask for read as well to
* speed up operation over network shares.
*/
handle = CreateFileW( path16, GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if( handle != INVALID_HANDLE_VALUE )
CloseHandle( handle );
}
#endif /*OS_WIN32*/
/* open() with a utf8 filename, setting errno. /* open() with a utf8 filename, setting errno.
*/ */
int int
@ -566,6 +589,9 @@ vips__open( const char *filename, int flags, ... )
return( -1 ); return( -1 );
} }
if( mode & O_CREAT )
vips__delete_create( path16 );
fd = _wopen( path16, flags, mode ); fd = _wopen( path16, flags, mode );
g_free( path16 ); g_free( path16 );
@ -606,6 +632,9 @@ vips__fopen( const char *filename, const char *mode )
return( NULL ); return( NULL );
} }
if( mode[0] == 'w' )
vips__delete_create( path16 );
fp = _wfopen( path16, mode16 ); fp = _wfopen( path16, mode16 );
g_free( path16 ); g_free( path16 );