Changeset 895


Ignore:
Timestamp:
31/08/2006 23:44:18 (5 years ago)
Author:
chris
Message:

Revert to trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/chris/merge/lib/raidfile/RaidFileWrite.cpp

    r710 r895  
    105105 
    106106        // Attempt to open 
    107         mOSFileHandle = ::open(writeFilename.c_str(),  
    108                 O_WRONLY | O_CREAT | O_BINARY, 
     107        mOSFileHandle = ::open(writeFilename.c_str(), O_WRONLY | O_CREAT, 
    109108                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 
    110109        if(mOSFileHandle == -1) 
     
    117116        int errnoBlock = EWOULDBLOCK; 
    118117        if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) 
    119 #elif HAVE_DECL_F_SETLK 
     118#else 
    120119        int errnoBlock = EAGAIN; 
    121120        struct flock desc; 
     
    125124        desc.l_len = 0; 
    126125        if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0) 
    127 #else 
    128         int errnoBlock = ENOSYS; 
    129         if (0) 
    130126#endif 
    131127        { 
     
    247243         
    248244        // Rename it into place -- BEFORE it's closed so lock remains 
    249  
    250 #ifdef WIN32 
    251         // Except on Win32 which doesn't allow renaming open files 
    252         // Close file... 
    253         if(::close(mOSFileHandle) != 0) 
    254         { 
    255                 THROW_EXCEPTION(RaidFileException, OSError) 
    256         } 
    257         mOSFileHandle = -1; 
    258 #endif // WIN32 
    259  
    260245        RaidFileController &rcontroller(RaidFileController::GetController()); 
    261246        RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(mSetNumber)); 
     
    264249        // And the current name 
    265250        std::string renameFrom(renameTo + 'X'); 
    266  
    267 #ifdef WIN32 
    268         // need to delete the target first 
    269         if(::unlink(renameTo.c_str()) != 0 &&  
    270                 GetLastError() != ERROR_FILE_NOT_FOUND) 
    271         { 
    272                 THROW_EXCEPTION(RaidFileException, OSError) 
    273         } 
    274 #endif 
    275  
    276251        if(::rename(renameFrom.c_str(), renameTo.c_str()) != 0) 
    277252        { 
     
    279254        } 
    280255         
    281 #ifndef WIN32    
    282256        // Close file... 
    283257        if(::close(mOSFileHandle) != 0) 
     
    286260        } 
    287261        mOSFileHandle = -1; 
    288 #endif // !WIN32 
    289262         
    290263        // Raid it? 
     
    320293         
    321294        // Unlink and close it 
    322  
    323 #ifdef WIN32 
    324         // On Win32 we must close it first 
    325         if (::close(mOSFileHandle) != 0 || 
    326                 ::unlink(writeFilename.c_str()) != 0) 
    327 #else // !WIN32 
    328         if (::unlink(writeFilename.c_str()) != 0 || 
    329                 ::close(mOSFileHandle) != 0) 
    330 #endif // !WIN32 
     295        if((::unlink(writeFilename.c_str()) != 0) 
     296                || (::close(mOSFileHandle) != 0)) 
    331297        { 
    332298                THROW_EXCEPTION(RaidFileException, OSError) 
     
    423389        { 
    424390#if HAVE_DECL_O_EXLOCK 
    425                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> stripe1(stripe1FilenameW.c_str()); 
    426                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> stripe2(stripe2FilenameW.c_str()); 
    427                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK | O_BINARY)> parity(parityFilenameW.c_str()); 
     391                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe1(stripe1FilenameW.c_str()); 
     392                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe2(stripe2FilenameW.c_str()); 
     393                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> parity(parityFilenameW.c_str()); 
    428394#else 
    429                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> stripe1(stripe1FilenameW.c_str()); 
    430                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> stripe2(stripe2FilenameW.c_str()); 
    431                 FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_BINARY)> parity(parityFilenameW.c_str()); 
     395                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str()); 
     396                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str()); 
     397                FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str()); 
    432398#endif 
    433399 
     
    565531                stripe2.Close(); 
    566532                stripe1.Close(); 
    567  
    568 #ifdef WIN32 
    569                 // Must delete before renaming 
    570                 #define CHECK_UNLINK(file) \ 
    571                 { \ 
    572                         if (::unlink(file) != 0 && errno != ENOENT) \ 
    573                         { \ 
    574                                 THROW_EXCEPTION(RaidFileException, OSError); \ 
    575                         } \ 
    576                 } 
    577                 CHECK_UNLINK(stripe1Filename.c_str()); 
    578                 CHECK_UNLINK(stripe2Filename.c_str()); 
    579                 CHECK_UNLINK(parityFilename.c_str()); 
    580                 #undef CHECK_UNLINK 
    581 #endif 
    582533                 
    583534                // Rename them into place 
Note: See TracChangeset for help on using the changeset viewer.