Changeset 2282
- Timestamp:
- 13/09/2008 15:29:26 (2 years ago)
- Location:
- box/trunk/bin/bbstored
- Files:
-
- 4 modified
-
BackupCommands.cpp (modified) (1 diff)
-
BackupStoreContext.cpp (modified) (3 diffs)
-
BackupStoreContext.h (modified) (1 diff)
-
backupprotocol.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/bin/bbstored/BackupCommands.cpp
r2226 r2282 611 611 // 612 612 // Function 613 // Name: BackupProtocolServerUndeleteFile::DoCommand( 614 // BackupProtocolServer &, BackupStoreContext &) 615 // Purpose: Undelete a file 616 // Created: 2008-09-12 617 // 618 // -------------------------------------------------------------------------- 619 std::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 613 637 // Name: BackupProtocolServerDeleteDirectory::DoCommand(BackupProtocolServer &, BackupStoreContext &) 614 638 // Purpose: Delete a directory -
box/trunk/bin/bbstored/BackupStoreContext.cpp
r2262 r2282 696 696 THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded) 697 697 } 698 698 699 if(mReadOnly) 699 700 { … … 760 761 throw; 761 762 } 762 763 763 764 764 return fileExisted; … … 766 766 767 767 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 // -------------------------------------------------------------------------- 776 bool 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 } 768 848 769 849 -
box/trunk/bin/bbstored/BackupStoreContext.h
r2262 r2282 113 113 bool ChangeFileAttributes(const BackupStoreFilename &rFilename, int64_t InDirectory, const StreamableMemBlock &Attributes, int64_t AttributesHash, int64_t &rObjectIDOut); 114 114 bool DeleteFile(const BackupStoreFilename &rFilename, int64_t InDirectory, int64_t &rObjectIDOut); 115 bool UndeleteFile(int64_t ObjectID, int64_t InDirectory); 115 116 void DeleteDirectory(int64_t ObjectID, bool Undelete = false); 116 117 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 205 205 206 206 207 UndeleteFile 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 207 213 # ------------------------------------------------------------------------------------- 208 214 # Information commands
