Ignore:
Timestamp:
05/07/2009 22:43:57 (3 years ago)
Author:
chris
Message:

Allow RaidFileWrite? to test that the reference count of an object is
correct before overwriting or deleting it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/raidfile/RaidFileWrite.cpp

    r2529 r2543  
    4343// Function 
    4444//              Name:    RaidFileWrite::RaidFileWrite(int, const std::string &) 
    45 //              Purpose: Construtor, just stores requried details 
     45//              Purpose: Simple constructor, just stores required details 
    4646//              Created: 2003/07/10 
    4747// 
     
    5050        : mSetNumber(SetNumber), 
    5151          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// -------------------------------------------------------------------------- 
     67RaidFileWrite::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        } 
    5484} 
    5585 
     
    251281                THROW_EXCEPTION(RaidFileException, NotOpen) 
    252282        } 
    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 
    254292        // Rename it into place -- BEFORE it's closed so lock remains 
    255293 
     
    639677void RaidFileWrite::Delete() 
    640678{ 
     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 
    641687        // Get disc set 
    642688        RaidFileController &rcontroller(RaidFileController::GetController()); 
Note: See TracChangeset for help on using the changeset viewer.