Ticket #108: flint_table.cc.2.patch

File flint_table.cc.2.patch, 1.2 KB (added by Charlie Hull, 18 years ago)

Patch to create files that can be deleted while open (Windows only)

  • flint_table.cc

     
    2323#include <config.h>
    2424
    2525#include "safeerrno.h"
    26 
     26#include "safewindows.h"
    2727// Define to use "dangerous" mode - in this mode we write modified btree
    2828// blocks back in place.  This is somewhat faster (especially once we're
    2929// I/O bound) but the database can't be safely searched during indexing
     
    130130
    131131static void sys_unlink(const string &filename)
    132132{
     133#ifdef _MSC_VER
     134        /* We must use DeleteFile as this can delete files that are open */
     135        if(DeleteFile(filename.c_str()) == 0) {
     136                DWORD dwErr = GetLastError();
     137                switch(dwErr){
     138                        case ERROR_FILE_NOT_FOUND: _set_errno(ENOENT); break;
     139                        case ERROR_SHARING_VIOLATION:
     140                                /* The file should have been opened with FILE_SHARE_DELETE if it is allowed
     141                                to be deleted, so if we get a sharing violation something's gone wrong */
     142                        case ERROR_ACCESS_DENIED: _set_errno(EACCES); break;
     143                }
     144#else   
    133145    if (unlink(filename) == -1) {
     146#endif
    134147        string message = "Failed to unlink ";
    135148        message += filename;
    136149        message += ": ";