Changeset 2282

Show
Ignore:
Timestamp:
13/09/2008 15:29:26 (2 years ago)
Author:
chris
Message:

Add command to undelete a file, to complete the set of commands
implemented by the bbstored server.

Location:
box/trunk/bin/bbstored
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbstored/BackupCommands.cpp

    r2226 r2282  
    611611// 
    612612// Function 
     613//              Name:    BackupProtocolServerUndeleteFile::DoCommand( 
     614//                       BackupProtocolServer &, BackupStoreContext &) 
     615//              Purpose: Undelete a file 
     616//              Created: 2008-09-12 
     617// 
     618// -------------------------------------------------------------------------- 
     619std::auto_ptr<ProtocolObject> BackupProtocolServerUndeleteFile::DoCommand( 
     620        BackupProtocolServer &rProtocol, BackupStoreContext &rContext) 
     621{ 
     622        CHECK_PHASE(Phase_Commands) 
     623        CHECK_WRITEABLE_SESSION 
     624 
     625        // Context handles this 
     626        bool result = rContext.UndeleteFile(mObjectID, mInDirectory); 
     627 
     628        // return the object ID or zero for not found 
     629        return std::auto_ptr<ProtocolObject>( 
     630                new BackupProtocolServerSuccess(result ? mObjectID : 0)); 
     631} 
     632 
     633 
     634// -------------------------------------------------------------------------- 
     635// 
     636// Function 
    613637//              Name:    BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) 
    614638//              Purpose: Delete a directory 
  • box/trunk/bin/bbstored/BackupStoreContext.cpp

    r2262 r2282  
    696696                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
    697697        } 
     698 
    698699        if(mReadOnly) 
    699700        { 
     
    760761                throw; 
    761762        } 
    762                  
    763763 
    764764        return fileExisted; 
     
    766766 
    767767 
     768// -------------------------------------------------------------------------- 
     769// 
     770// Function 
     771//              Name:    BackupStoreContext::DeleteFile(const BackupStoreFilename &, int64_t, int64_t &) 
     772//              Purpose: Deletes a file, returning true if the file existed. Object ID returned too, set to zero if not found. 
     773//              Created: 2003/10/21 
     774// 
     775// -------------------------------------------------------------------------- 
     776bool BackupStoreContext::UndeleteFile(int64_t ObjectID, int64_t InDirectory) 
     777{ 
     778        // Essential checks! 
     779        if(mpStoreInfo.get() == 0) 
     780        { 
     781                THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 
     782        } 
     783 
     784        if(mReadOnly) 
     785        { 
     786                THROW_EXCEPTION(BackupStoreException, ContextIsReadOnly) 
     787        } 
     788 
     789        // Find the directory the file is in (will exception if it fails) 
     790        BackupStoreDirectory &dir(GetDirectoryInternal(InDirectory)); 
     791 
     792        // Setup flags 
     793        bool fileExisted = false; 
     794        bool madeChanges = false; 
     795 
     796        // Count of deleted blocks 
     797        int64_t blocksDel = 0; 
     798 
     799        try 
     800        { 
     801                // Iterate through directory, only looking at files which have been deleted 
     802                BackupStoreDirectory::Iterator i(dir); 
     803                BackupStoreDirectory::Entry *e = 0; 
     804                while((e = i.Next(BackupStoreDirectory::Entry::Flags_File | 
     805                        BackupStoreDirectory::Entry::Flags_Deleted, 0)) != 0) 
     806                { 
     807                        // Compare name 
     808                        if(e->GetObjectID() == ObjectID) 
     809                        { 
     810                                // Check that it's definitely already deleted 
     811                                ASSERT((e->GetFlags() & BackupStoreDirectory::Entry::Flags_Deleted) != 0); 
     812                                // Clear deleted flag 
     813                                e->RemoveFlags(BackupStoreDirectory::Entry::Flags_Deleted); 
     814                                // Mark as made a change 
     815                                madeChanges = true; 
     816                                blocksDel -= e->GetSizeInBlocks(); 
     817 
     818                                // Is this the last version? 
     819                                if((e->GetFlags() & BackupStoreDirectory::Entry::Flags_OldVersion) == 0) 
     820                                { 
     821                                        // Yes. It's been found. 
     822                                        fileExisted = true; 
     823                                } 
     824                        } 
     825                } 
     826                 
     827                // Save changes? 
     828                if(madeChanges) 
     829                { 
     830                        // Save the directory back 
     831                        SaveDirectory(dir, InDirectory); 
     832                         
     833                        // Modify the store info, and write 
     834                        mpStoreInfo->ChangeBlocksInDeletedFiles(blocksDel); 
     835                         
     836                        // Maybe postponed save of store info 
     837                        SaveStoreInfo(); 
     838                } 
     839        } 
     840        catch(...) 
     841        { 
     842                RemoveDirectoryFromCache(InDirectory); 
     843                throw; 
     844        } 
     845 
     846        return fileExisted; 
     847} 
    768848 
    769849 
  • box/trunk/bin/bbstored/BackupStoreContext.h

    r2262 r2282  
    113113        bool ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut); 
    114114        bool DeleteFile(const BackupStoreFilename &rFilename, int64_t InDirectory, int64_t &rObjectIDOut); 
     115        bool UndeleteFile(int64_t ObjectID, int64_t InDirectory); 
    115116        void DeleteDirectory(int64_t ObjectID, bool Undelete = false); 
    116117        void MoveObject(int64_t ObjectID, int64_t MoveFromDirectory, int64_t MoveToDirectory, const BackupStoreFilename &rNewFilename, bool MoveAllWithSameName, bool AllowMoveOverDeletedObject); 
  • box/trunk/bin/bbstored/backupprotocol.txt

    r2226 r2282  
    205205 
    206206 
     207UndeleteFile    36      Command(Success) 
     208        int64           InDirectory 
     209        int64           ObjectID 
     210        # will return 0 if the object couldn't be found in the specified directory 
     211 
     212 
    207213# ------------------------------------------------------------------------------------- 
    208214#  Information commands