Ignore:
Timestamp:
13/09/2008 16:29:26 (3 years ago)
Author:
chris
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.