| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: BackupStoreInfo.h |
|---|
| 5 | // Purpose: Main backup store information storage |
|---|
| 6 | // Created: 2003/08/28 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef BACKUPSTOREINFO__H |
|---|
| 11 | #define BACKUPSTOREINFO__H |
|---|
| 12 | |
|---|
| 13 | #include <memory> |
|---|
| 14 | #include <string> |
|---|
| 15 | #include <vector> |
|---|
| 16 | |
|---|
| 17 | class BackupStoreCheck; |
|---|
| 18 | |
|---|
| 19 | // -------------------------------------------------------------------------- |
|---|
| 20 | // |
|---|
| 21 | // Class |
|---|
| 22 | // Name: BackupStoreInfo |
|---|
| 23 | // Purpose: Main backup store information storage |
|---|
| 24 | // Created: 2003/08/28 |
|---|
| 25 | // |
|---|
| 26 | // -------------------------------------------------------------------------- |
|---|
| 27 | class BackupStoreInfo |
|---|
| 28 | { |
|---|
| 29 | friend class BackupStoreCheck; |
|---|
| 30 | public: |
|---|
| 31 | ~BackupStoreInfo(); |
|---|
| 32 | private: |
|---|
| 33 | // Creation through static functions only |
|---|
| 34 | BackupStoreInfo(); |
|---|
| 35 | // No copying allowed |
|---|
| 36 | BackupStoreInfo(const BackupStoreInfo &); |
|---|
| 37 | |
|---|
| 38 | public: |
|---|
| 39 | // Create a New account, saving a blank info object to the disc |
|---|
| 40 | static void CreateNew(int32_t AccountID, const std::string &rRootDir, int DiscSet, int64_t BlockSoftLimit, int64_t BlockHardLimit); |
|---|
| 41 | |
|---|
| 42 | // Load it from the store |
|---|
| 43 | static std::auto_ptr<BackupStoreInfo> Load(int32_t AccountID, const std::string &rRootDir, int DiscSet, bool ReadOnly, int64_t *pRevisionID = 0); |
|---|
| 44 | |
|---|
| 45 | // Has info been modified? |
|---|
| 46 | bool IsModified() const {return mIsModified;} |
|---|
| 47 | |
|---|
| 48 | // Save modified infomation back to store |
|---|
| 49 | void Save(bool allowOverwrite = true); |
|---|
| 50 | |
|---|
| 51 | // Data access functions |
|---|
| 52 | int32_t GetAccountID() const {return mAccountID;} |
|---|
| 53 | int64_t GetLastObjectIDUsed() const {return mLastObjectIDUsed;} |
|---|
| 54 | int64_t GetBlocksUsed() const {return mBlocksUsed;} |
|---|
| 55 | int64_t GetBlocksInCurrentFiles() const {return mBlocksInCurrentFiles;} |
|---|
| 56 | int64_t GetBlocksInOldFiles() const {return mBlocksInOldFiles;} |
|---|
| 57 | int64_t GetBlocksInDeletedFiles() const {return mBlocksInDeletedFiles;} |
|---|
| 58 | int64_t GetBlocksInDirectories() const {return mBlocksInDirectories;} |
|---|
| 59 | const std::vector<int64_t> &GetDeletedDirectories() const {return mDeletedDirectories;} |
|---|
| 60 | int64_t GetBlocksSoftLimit() const {return mBlocksSoftLimit;} |
|---|
| 61 | int64_t GetBlocksHardLimit() const {return mBlocksHardLimit;} |
|---|
| 62 | int64_t GetNumFiles() const {return mNumFiles;} |
|---|
| 63 | int64_t GetNumOldFiles() const {return mNumOldFiles;} |
|---|
| 64 | int64_t GetNumDeletedFiles() const {return mNumDeletedFiles;} |
|---|
| 65 | int64_t GetNumDirectories() const {return mNumDirectories;} |
|---|
| 66 | bool IsReadOnly() const {return mReadOnly;} |
|---|
| 67 | int GetDiscSetNumber() const {return mDiscSet;} |
|---|
| 68 | |
|---|
| 69 | int ReportChangesTo(BackupStoreInfo& rOldInfo); |
|---|
| 70 | |
|---|
| 71 | // Data modification functions |
|---|
| 72 | void ChangeBlocksUsed(int64_t Delta); |
|---|
| 73 | void ChangeBlocksInCurrentFiles(int64_t Delta); |
|---|
| 74 | void ChangeBlocksInOldFiles(int64_t Delta); |
|---|
| 75 | void ChangeBlocksInDeletedFiles(int64_t Delta); |
|---|
| 76 | void ChangeBlocksInDirectories(int64_t Delta); |
|---|
| 77 | void CorrectAllUsedValues(int64_t Used, int64_t InOldFiles, int64_t InDeletedFiles, int64_t InDirectories); |
|---|
| 78 | void AddDeletedDirectory(int64_t DirID); |
|---|
| 79 | void RemovedDeletedDirectory(int64_t DirID); |
|---|
| 80 | void ChangeLimits(int64_t BlockSoftLimit, int64_t BlockHardLimit); |
|---|
| 81 | void AdjustNumFiles(int64_t increase); |
|---|
| 82 | void AdjustNumOldFiles(int64_t increase); |
|---|
| 83 | void AdjustNumDeletedFiles(int64_t increase); |
|---|
| 84 | void AdjustNumDirectories(int64_t increase); |
|---|
| 85 | |
|---|
| 86 | // Object IDs |
|---|
| 87 | int64_t AllocateObjectID(); |
|---|
| 88 | |
|---|
| 89 | // Client marker set and get |
|---|
| 90 | int64_t GetClientStoreMarker() {return mClientStoreMarker;} |
|---|
| 91 | void SetClientStoreMarker(int64_t ClientStoreMarker); |
|---|
| 92 | |
|---|
| 93 | const std::string& GetAccountName() { return mAccountName; } |
|---|
| 94 | void SetAccountName(const std::string& rName); |
|---|
| 95 | |
|---|
| 96 | private: |
|---|
| 97 | static std::auto_ptr<BackupStoreInfo> CreateForRegeneration( |
|---|
| 98 | int32_t AccountID, const std::string &rAccountName, |
|---|
| 99 | const std::string &rRootDir, int DiscSet, |
|---|
| 100 | int64_t LastObjectID, int64_t BlocksUsed, |
|---|
| 101 | int64_t BlocksInCurrentFiles, int64_t BlocksInOldFiles, |
|---|
| 102 | int64_t BlocksInDeletedFiles, int64_t BlocksInDirectories, |
|---|
| 103 | int64_t BlockSoftLimit, int64_t BlockHardLimit); |
|---|
| 104 | |
|---|
| 105 | // Location information |
|---|
| 106 | // Be VERY careful about changing types of these values, as |
|---|
| 107 | // they now define the sizes of fields on disk (via Archive). |
|---|
| 108 | int32_t mAccountID; |
|---|
| 109 | std::string mAccountName; |
|---|
| 110 | int mDiscSet; |
|---|
| 111 | std::string mFilename; |
|---|
| 112 | bool mReadOnly; |
|---|
| 113 | bool mIsModified; |
|---|
| 114 | |
|---|
| 115 | // Client infomation |
|---|
| 116 | int64_t mClientStoreMarker; |
|---|
| 117 | |
|---|
| 118 | // Account information |
|---|
| 119 | int64_t mLastObjectIDUsed; |
|---|
| 120 | int64_t mBlocksUsed; |
|---|
| 121 | int64_t mBlocksInCurrentFiles; |
|---|
| 122 | int64_t mBlocksInOldFiles; |
|---|
| 123 | int64_t mBlocksInDeletedFiles; |
|---|
| 124 | int64_t mBlocksInDirectories; |
|---|
| 125 | int64_t mBlocksSoftLimit; |
|---|
| 126 | int64_t mBlocksHardLimit; |
|---|
| 127 | int64_t mNumFiles; |
|---|
| 128 | int64_t mNumOldFiles; |
|---|
| 129 | int64_t mNumDeletedFiles; |
|---|
| 130 | int64_t mNumDirectories; |
|---|
| 131 | std::vector<int64_t> mDeletedDirectories; |
|---|
| 132 | }; |
|---|
| 133 | |
|---|
| 134 | #endif // BACKUPSTOREINFO__H |
|---|
| 135 | |
|---|
| 136 | |
|---|