Changeset 896 for box/chris/merge/lib/raidfile/RaidFileWrite.cpp
- Timestamp:
- 31/08/2006 23:50:02 (6 years ago)
- File:
-
- 1 edited
-
box/chris/merge/lib/raidfile/RaidFileWrite.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/chris/merge/lib/raidfile/RaidFileWrite.cpp
r895 r896 105 105 106 106 // Attempt to open 107 mOSFileHandle = ::open(writeFilename.c_str(), O_WRONLY | O_CREAT, 107 mOSFileHandle = ::open(writeFilename.c_str(), 108 O_WRONLY | O_CREAT | O_BINARY, 108 109 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 109 110 if(mOSFileHandle == -1) … … 116 117 int errnoBlock = EWOULDBLOCK; 117 118 if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) 118 #el se119 #elif HAVE_DECL_F_SETLK 119 120 int errnoBlock = EAGAIN; 120 121 struct flock desc; … … 124 125 desc.l_len = 0; 125 126 if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0) 127 #else 128 int errnoBlock = ENOSYS; 129 if (0) 126 130 #endif 127 131 { … … 243 247 244 248 // 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 245 260 RaidFileController &rcontroller(RaidFileController::GetController()); 246 261 RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(mSetNumber)); … … 249 264 // And the current name 250 265 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 251 276 if(::rename(renameFrom.c_str(), renameTo.c_str()) != 0) 252 277 { … … 254 279 } 255 280 281 #ifndef WIN32 256 282 // Close file... 257 283 if(::close(mOSFileHandle) != 0) … … 260 286 } 261 287 mOSFileHandle = -1; 288 #endif // !WIN32 262 289 263 290 // Raid it? … … 293 320 294 321 // Unlink and close it 295 if((::unlink(writeFilename.c_str()) != 0) 296 || (::close(mOSFileHandle) != 0)) 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 297 331 { 298 332 THROW_EXCEPTION(RaidFileException, OSError) … … 389 423 { 390 424 #if HAVE_DECL_O_EXLOCK 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());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()); 394 428 #else 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());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()); 398 432 #endif 399 433 … … 531 565 stripe2.Close(); 532 566 stripe1.Close(); 567 568 #ifdef WIN32 569 // Must delete before renaming 570 if (::unlink(stripe1Filename.c_str()) != 0 && errno != ENOENT) 571 { 572 THROW_EXCEPTION(RaidFileException, OSError); 573 } 574 if (::unlink(stripe2Filename.c_str()) != 0 && errno != ENOENT) 575 { 576 THROW_EXCEPTION(RaidFileException, OSError); 577 } 578 if (::unlink(parityFilename.c_str()) != 0 && errno != ENOENT) 579 { 580 THROW_EXCEPTION(RaidFileException, OSError); 581 } 582 #endif 533 583 534 584 // Rename them into place
Note: See TracChangeset
for help on using the changeset viewer.
