Changeset 895
- Timestamp:
- 31/08/2006 23:44:18 (5 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
r710 r895 105 105 106 106 // 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, 109 108 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 110 109 if(mOSFileHandle == -1) … … 117 116 int errnoBlock = EWOULDBLOCK; 118 117 if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) 119 #el if HAVE_DECL_F_SETLK118 #else 120 119 int errnoBlock = EAGAIN; 121 120 struct flock desc; … … 125 124 desc.l_len = 0; 126 125 if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0) 127 #else128 int errnoBlock = ENOSYS;129 if (0)130 126 #endif 131 127 { … … 247 243 248 244 // Rename it into place -- BEFORE it's closed so lock remains 249 250 #ifdef WIN32251 // Except on Win32 which doesn't allow renaming open files252 // Close file...253 if(::close(mOSFileHandle) != 0)254 {255 THROW_EXCEPTION(RaidFileException, OSError)256 }257 mOSFileHandle = -1;258 #endif // WIN32259 260 245 RaidFileController &rcontroller(RaidFileController::GetController()); 261 246 RaidFileDiscSet rdiscSet(rcontroller.GetDiscSet(mSetNumber)); … … 264 249 // And the current name 265 250 std::string renameFrom(renameTo + 'X'); 266 267 #ifdef WIN32268 // need to delete the target first269 if(::unlink(renameTo.c_str()) != 0 &&270 GetLastError() != ERROR_FILE_NOT_FOUND)271 {272 THROW_EXCEPTION(RaidFileException, OSError)273 }274 #endif275 276 251 if(::rename(renameFrom.c_str(), renameTo.c_str()) != 0) 277 252 { … … 279 254 } 280 255 281 #ifndef WIN32282 256 // Close file... 283 257 if(::close(mOSFileHandle) != 0) … … 286 260 } 287 261 mOSFileHandle = -1; 288 #endif // !WIN32289 262 290 263 // Raid it? … … 320 293 321 294 // 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)) 331 297 { 332 298 THROW_EXCEPTION(RaidFileException, OSError) … … 423 389 { 424 390 #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()); 428 394 #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()); 432 398 #endif 433 399 … … 565 531 stripe2.Close(); 566 532 stripe1.Close(); 567 568 #ifdef WIN32569 // Must delete before renaming570 #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_UNLINK581 #endif582 533 583 534 // Rename them into place
Note: See TracChangeset
for help on using the changeset viewer.
