Hi,

winDelete in os_win.c has retry functionality to try multiple times to
delete a file if a virus scanner or indexing program has a handle open
on that file.  We've seen SQLite failures that have been tracked down to
other apps temporarily opening our db journal files, so we believe that
the retry behavior could be very valuable to us.

In order to check for failure, winDelete checks that DeleteFileW returns
zero and that GetFileAttributesW doesn't return INVALID_FILE_ATTRIBUTES.
However, when I try calling DeleteFileW on a file with a handle open on
that file, I see DeleteFileW returning 1 (success) and I see
GetFileAttributesW returning INVALID_FILE_ATTRIBUTES, I think because
even though the file still exists it is in a "delete pending" state.

The code below illustrates the problem.  Thanks for any help you can
provide!

:) Jeremy Spiegel


#include <stdio.h>
#include <tchar.h>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{    
        DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
        DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE;
        DWORD dwCreationDisposition = OPEN_ALWAYS;
        DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
                | FILE_ATTRIBUTE_HIDDEN
                | FILE_FLAG_DELETE_ON_CLOSE
                | FILE_FLAG_RANDOM_ACCESS;

        HANDLE h = CreateFileW(L"c:\\test.txt",
                dwDesiredAccess,
                dwShareMode,
                NULL,
                dwCreationDisposition,
                dwFlagsAndAttributes,
                NULL
                );

        if( h==INVALID_HANDLE_VALUE )
                printf("error\n");

        int rc = DeleteFileW( L"c:\\test.txt" );
        if ( rc == 0 )
                printf("DeleteFileW failed\n");

        if ( GetFileAttributesW( L"c:\\test.txt" ) != 0xffffffff )
                printf( "File still exists\n");

        HANDLE h2 = CreateFileW(L"c:\\test.txt",
                dwDesiredAccess,
                dwShareMode,
                NULL,
                dwCreationDisposition,
                dwFlagsAndAttributes,
                NULL
                );

        if ( h2 == INVALID_HANDLE_VALUE )
                printf( "Error: 0x%x", GetLastError() );
        
        CloseHandle(h);
        return 0;
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to