- Timestamp:
- 05/07/2009 22:43:57 (3 years ago)
- Location:
- box/trunk
- Files:
-
- 4 edited
-
lib/raidfile/RaidFileException.txt (modified) (1 diff)
-
lib/raidfile/RaidFileWrite.cpp (modified) (4 diffs)
-
lib/raidfile/RaidFileWrite.h (modified) (2 diffs)
-
test/raidfile/testraidfile.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/raidfile/RaidFileException.txt
r1519 r2543 24 24 ErrorOpeningWriteFileOnTruncate 21 25 25 FileIsCurrentlyOpenForWriting 22 26 RequestedModifyUnreferencedFile 23 Internal error: the server attempted to modify a file which has no references. 27 RequestedModifyMultiplyReferencedFile 24 Internal error: the server attempted to modify a file which has multiple references. 28 RequestedDeleteReferencedFile 25 Internal error: the server attempted to delete a file which is still referenced. -
box/trunk/lib/raidfile/RaidFileWrite.cpp
r2529 r2543 43 43 // Function 44 44 // Name: RaidFileWrite::RaidFileWrite(int, const std::string &) 45 // Purpose: Construtor, just stores requried details45 // Purpose: Simple constructor, just stores required details 46 46 // Created: 2003/07/10 47 47 // … … 50 50 : mSetNumber(SetNumber), 51 51 mFilename(Filename), 52 mOSFileHandle(-1) // not valid file handle 53 { 52 mOSFileHandle(-1), // not valid file handle 53 mRefCount(-1) // unknown refcount 54 { 55 } 56 57 // -------------------------------------------------------------------------- 58 // 59 // Function 60 // Name: RaidFileWrite::RaidFileWrite(int, 61 // const std::string &, int refcount) 62 // Purpose: Constructor with check for overwriting file 63 // with multiple references 64 // Created: 2009/07/05 65 // 66 // -------------------------------------------------------------------------- 67 RaidFileWrite::RaidFileWrite(int SetNumber, const std::string &Filename, 68 int refcount) 69 : mSetNumber(SetNumber), 70 mFilename(Filename), 71 mOSFileHandle(-1), // not valid file handle 72 mRefCount(refcount) 73 { 74 // Can't check for zero refcount here, because it's legal 75 // to create a RaidFileWrite to delete an object with zero refcount. 76 // Check in Commit() and Delete() instead. 77 if (refcount > 1) 78 { 79 BOX_ERROR("Attempted to modify object " << mFilename << 80 ", which has " << refcount << " references"); 81 THROW_EXCEPTION(RaidFileException, 82 RequestedModifyMultiplyReferencedFile); 83 } 54 84 } 55 85 … … 251 281 THROW_EXCEPTION(RaidFileException, NotOpen) 252 282 } 253 283 284 if (mRefCount == 0) 285 { 286 BOX_ERROR("Attempted to modify object " << mFilename << 287 ", which has no references"); 288 THROW_EXCEPTION(RaidFileException, 289 RequestedModifyUnreferencedFile); 290 } 291 254 292 // Rename it into place -- BEFORE it's closed so lock remains 255 293 … … 639 677 void RaidFileWrite::Delete() 640 678 { 679 if (mRefCount != 0 && mRefCount != -1) 680 { 681 BOX_ERROR("Attempted to delete object " << mFilename << 682 " which has " << mRefCount << " references"); 683 THROW_EXCEPTION(RaidFileException, 684 RequestedDeleteReferencedFile); 685 } 686 641 687 // Get disc set 642 688 RaidFileController &rcontroller(RaidFileController::GetController()); -
box/trunk/lib/raidfile/RaidFileWrite.h
r217 r2543 29 29 public: 30 30 RaidFileWrite(int SetNumber, const std::string &Filename); 31 RaidFileWrite(int SetNumber, const std::string &Filename, int refcount); 31 32 ~RaidFileWrite(); 32 33 private: … … 61 62 std::string mFilename; 62 63 int mOSFileHandle; 64 int mRefCount; 63 65 }; 64 66 -
box/trunk/test/raidfile/testraidfile.cpp
r2506 r2543 628 628 } 629 629 630 // Test that creating and deleting a RaidFile with the wrong 631 // reference counts throws the expected errors. 632 { 633 RaidFileWrite write1(0, "write1", 1); 634 write1.Open(); 635 write1.Commit(); 636 TEST_CHECK_THROWS(write1.Delete(), RaidFileException, 637 RequestedDeleteReferencedFile); 638 } 639 640 { 641 RaidFileWrite write1(0, "write1", 0); 642 write1.Open(true); 643 TEST_CHECK_THROWS(write1.Commit(), RaidFileException, 644 RequestedModifyUnreferencedFile); 645 write1.Delete(); 646 } 647 648 { 649 TEST_CHECK_THROWS(RaidFileWrite write1(0, "write1", 2), 650 RaidFileException, 651 RequestedModifyMultiplyReferencedFile); 652 } 653 630 654 // Create a RaidFile 631 655 RaidFileWrite write1(0, "test1");
Note: See TracChangeset
for help on using the changeset viewer.
