From 6f4d8a67f7c492963b0ac96e136954d91c1ea0e6 Mon Sep 17 00:00:00 2001 From: yaworsky Date: Fri, 16 Sep 2005 10:23:10 +0000 Subject: Fixed file creation date workaround. --- daemon/writer.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'daemon') diff --git a/daemon/writer.c b/daemon/writer.c index ea4f915..e05a2c8 100644 --- a/daemon/writer.c +++ b/daemon/writer.c @@ -308,7 +308,6 @@ static unsigned __stdcall writer_thread_proc( void* arg ) struct file_writer *writer = arg; HANDLE wait_objects[2] = { writer->fifo_semaphore, writer->shutdown_event }; gchar *pathname; - FILETIME systime; TRACE_ENTER( "writer=%p\n", writer ); @@ -319,22 +318,28 @@ static unsigned __stdcall writer_thread_proc( void* arg ) writer->fd = CreateFile( pathname, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); - g_free( pathname ); if( INVALID_HANDLE_VALUE == writer->fd ) { ERR( "CreateFile(%s) error %lu\n", pathname, GetLastError() ); + g_free( pathname ); goto done; } - SetFilePointer( writer->fd, 0, NULL, FILE_END ); /* there's a strange bug or feature in windows: if there was a file with the same name in the directory, a new file will inherit its creation time; - because of this logs will be rotate each time; + because of this logs will be rotated each time; here is a workaround: */ - GetSystemTimeAsFileTime( &systime ); - if( !SetFileTime( writer->fd, &systime, &systime, &systime ) ) - ERR( "SetFileTime error %lu\n", GetLastError() ); + if( GetLastError() != ERROR_ALREADY_EXISTS ) + { + FILETIME systime; + GetSystemTimeAsFileTime( &systime ); + if( !SetFileTime( writer->fd, &systime, &systime, &systime ) ) + ERR( "SetFileTime error %lu\n", GetLastError() ); + } + + g_free( pathname ); + SetFilePointer( writer->fd, 0, NULL, FILE_END ); for(;;) { -- cgit v1.2.3