| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: BackupClientDirectoryRecord.h |
|---|
| 5 | // Purpose: Implementation of record about directory for backup client |
|---|
| 6 | // Created: 2003/10/08 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef BACKUPCLIENTDIRECTORYRECORD__H |
|---|
| 11 | #define BACKUPCLIENTDIRECTORYRECORD__H |
|---|
| 12 | |
|---|
| 13 | #include <string> |
|---|
| 14 | #include <map> |
|---|
| 15 | #include <memory> |
|---|
| 16 | |
|---|
| 17 | #include "BackupClientFileAttributes.h" |
|---|
| 18 | #include "BackupDaemonInterface.h" |
|---|
| 19 | #include "BackupStoreDirectory.h" |
|---|
| 20 | #include "BoxTime.h" |
|---|
| 21 | #include "MD5Digest.h" |
|---|
| 22 | #include "ReadLoggingStream.h" |
|---|
| 23 | #include "RunStatusProvider.h" |
|---|
| 24 | |
|---|
| 25 | #ifdef ENABLE_VSS |
|---|
| 26 | # include <comdef.h> |
|---|
| 27 | # include <Vss.h> |
|---|
| 28 | # include <VsWriter.h> |
|---|
| 29 | # include <VsBackup.h> |
|---|
| 30 | #endif |
|---|
| 31 | |
|---|
| 32 | class Archive; |
|---|
| 33 | class BackupClientContext; |
|---|
| 34 | class BackupDaemon; |
|---|
| 35 | class ExcludeList; |
|---|
| 36 | class Location; |
|---|
| 37 | |
|---|
| 38 | // -------------------------------------------------------------------------- |
|---|
| 39 | // |
|---|
| 40 | // Class |
|---|
| 41 | // Name: BackupClientDirectoryRecord |
|---|
| 42 | // Purpose: Implementation of record about directory for backup client |
|---|
| 43 | // Created: 2003/10/08 |
|---|
| 44 | // |
|---|
| 45 | // -------------------------------------------------------------------------- |
|---|
| 46 | class BackupClientDirectoryRecord |
|---|
| 47 | { |
|---|
| 48 | public: |
|---|
| 49 | BackupClientDirectoryRecord(int64_t ObjectID, const std::string &rSubDirName); |
|---|
| 50 | ~BackupClientDirectoryRecord(); |
|---|
| 51 | |
|---|
| 52 | void Deserialize(Archive & rArchive); |
|---|
| 53 | void Serialize(Archive & rArchive) const; |
|---|
| 54 | private: |
|---|
| 55 | BackupClientDirectoryRecord(const BackupClientDirectoryRecord &); |
|---|
| 56 | public: |
|---|
| 57 | |
|---|
| 58 | enum |
|---|
| 59 | { |
|---|
| 60 | UnknownDirectoryID = 0 |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | // -------------------------------------------------------------------------- |
|---|
| 64 | // |
|---|
| 65 | // Class |
|---|
| 66 | // Name: BackupClientDirectoryRecord::SyncParams |
|---|
| 67 | // Purpose: Holds parameters etc for directory syncing. Not passed as |
|---|
| 68 | // const, some parameters may be modified during sync. |
|---|
| 69 | // Created: 8/3/04 |
|---|
| 70 | // |
|---|
| 71 | // -------------------------------------------------------------------------- |
|---|
| 72 | class SyncParams : public ReadLoggingStream::Logger |
|---|
| 73 | { |
|---|
| 74 | public: |
|---|
| 75 | SyncParams( |
|---|
| 76 | RunStatusProvider &rRunStatusProvider, |
|---|
| 77 | SysadminNotifier &rSysadminNotifier, |
|---|
| 78 | ProgressNotifier &rProgressNotifier, |
|---|
| 79 | BackupClientContext &rContext); |
|---|
| 80 | ~SyncParams(); |
|---|
| 81 | private: |
|---|
| 82 | // No copying |
|---|
| 83 | SyncParams(const SyncParams&); |
|---|
| 84 | SyncParams &operator=(const SyncParams&); |
|---|
| 85 | |
|---|
| 86 | public: |
|---|
| 87 | // Data members are public, as accessors are not justified here |
|---|
| 88 | box_time_t mSyncPeriodStart; |
|---|
| 89 | box_time_t mSyncPeriodEnd; |
|---|
| 90 | box_time_t mMaxUploadWait; |
|---|
| 91 | box_time_t mMaxFileTimeInFuture; |
|---|
| 92 | int32_t mFileTrackingSizeThreshold; |
|---|
| 93 | int32_t mDiffingUploadSizeThreshold; |
|---|
| 94 | RunStatusProvider &mrRunStatusProvider; |
|---|
| 95 | SysadminNotifier &mrSysadminNotifier; |
|---|
| 96 | ProgressNotifier &mrProgressNotifier; |
|---|
| 97 | BackupClientContext &mrContext; |
|---|
| 98 | bool mReadErrorsOnFilesystemObjects; |
|---|
| 99 | int64_t mMaxUploadRate; |
|---|
| 100 | |
|---|
| 101 | // Member variables modified by syncing process |
|---|
| 102 | box_time_t mUploadAfterThisTimeInTheFuture; |
|---|
| 103 | bool mHaveLoggedWarningAboutFutureFileTimes; |
|---|
| 104 | |
|---|
| 105 | bool StopRun() { return mrRunStatusProvider.StopRun(); } |
|---|
| 106 | void NotifySysadmin(SysadminNotifier::EventCode Event) |
|---|
| 107 | { |
|---|
| 108 | mrSysadminNotifier.NotifySysadmin(Event); |
|---|
| 109 | } |
|---|
| 110 | ProgressNotifier& GetProgressNotifier() const |
|---|
| 111 | { |
|---|
| 112 | return mrProgressNotifier; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /* ReadLoggingStream::Logger implementation */ |
|---|
| 116 | virtual void Log(int64_t readSize, int64_t offset, |
|---|
| 117 | int64_t length, box_time_t elapsed, box_time_t finish) |
|---|
| 118 | { |
|---|
| 119 | mrProgressNotifier.NotifyReadProgress(readSize, offset, |
|---|
| 120 | length, elapsed, finish); |
|---|
| 121 | } |
|---|
| 122 | virtual void Log(int64_t readSize, int64_t offset, |
|---|
| 123 | int64_t length) |
|---|
| 124 | { |
|---|
| 125 | mrProgressNotifier.NotifyReadProgress(readSize, offset, |
|---|
| 126 | length); |
|---|
| 127 | } |
|---|
| 128 | virtual void Log(int64_t readSize, int64_t offset) |
|---|
| 129 | { |
|---|
| 130 | mrProgressNotifier.NotifyReadProgress(readSize, offset); |
|---|
| 131 | } |
|---|
| 132 | }; |
|---|
| 133 | |
|---|
| 134 | void SyncDirectory(SyncParams &rParams, |
|---|
| 135 | int64_t ContainingDirectoryID, |
|---|
| 136 | const std::string &rLocalPath, |
|---|
| 137 | const std::string &rRemotePath, |
|---|
| 138 | const Location& rBackupLocation, |
|---|
| 139 | bool ThisDirHasJustBeenCreated = false); |
|---|
| 140 | |
|---|
| 141 | std::string ConvertVssPathToRealPath(const std::string &rVssPath, |
|---|
| 142 | const Location& rBackupLocation); |
|---|
| 143 | |
|---|
| 144 | int64_t GetObjectID() const { return mObjectID; } |
|---|
| 145 | |
|---|
| 146 | private: |
|---|
| 147 | void DeleteSubDirectories(); |
|---|
| 148 | BackupStoreDirectory *FetchDirectoryListing(SyncParams &rParams); |
|---|
| 149 | void UpdateAttributes(SyncParams &rParams, |
|---|
| 150 | BackupStoreDirectory *pDirOnStore, |
|---|
| 151 | const std::string &rLocalPath); |
|---|
| 152 | bool UpdateItems(SyncParams &rParams, const std::string &rLocalPath, |
|---|
| 153 | const std::string &rRemotePath, |
|---|
| 154 | const Location& rBackupLocation, |
|---|
| 155 | BackupStoreDirectory *pDirOnStore, |
|---|
| 156 | std::vector<BackupStoreDirectory::Entry *> &rEntriesLeftOver, |
|---|
| 157 | std::vector<std::string> &rFiles, |
|---|
| 158 | const std::vector<std::string> &rDirs); |
|---|
| 159 | int64_t UploadFile(SyncParams &rParams, |
|---|
| 160 | const std::string &rFilename, |
|---|
| 161 | const std::string &rNonVssFilePath, |
|---|
| 162 | const BackupStoreFilename &rStoreFilename, |
|---|
| 163 | int64_t FileSize, box_time_t ModificationTime, |
|---|
| 164 | box_time_t AttributesHash, bool NoPreviousVersionOnServer); |
|---|
| 165 | void SetErrorWhenReadingFilesystemObject(SyncParams &rParams, |
|---|
| 166 | const std::string& rFilename); |
|---|
| 167 | void RemoveDirectoryInPlaceOfFile(SyncParams &rParams, |
|---|
| 168 | BackupStoreDirectory* pDirOnStore, |
|---|
| 169 | BackupStoreDirectory::Entry* pEntry, |
|---|
| 170 | const std::string &rFilename); |
|---|
| 171 | std::string DecryptFilename(BackupStoreDirectory::Entry *en, |
|---|
| 172 | const std::string& rRemoteDirectoryPath); |
|---|
| 173 | std::string DecryptFilename(BackupStoreFilenameClear fn, |
|---|
| 174 | int64_t filenameObjectID, |
|---|
| 175 | const std::string& rRemoteDirectoryPath); |
|---|
| 176 | |
|---|
| 177 | int64_t mObjectID; |
|---|
| 178 | std::string mSubDirName; |
|---|
| 179 | bool mInitialSyncDone; |
|---|
| 180 | bool mSyncDone; |
|---|
| 181 | bool mSuppressMultipleLinksWarning; |
|---|
| 182 | |
|---|
| 183 | // Checksum of directory contents and attributes, used to detect changes |
|---|
| 184 | uint8_t mStateChecksum[MD5Digest::DigestLength]; |
|---|
| 185 | |
|---|
| 186 | std::map<std::string, box_time_t> *mpPendingEntries; |
|---|
| 187 | std::map<std::string, BackupClientDirectoryRecord *> mSubDirectories; |
|---|
| 188 | // mpPendingEntries is a pointer rather than simple a member |
|---|
| 189 | // variable, because most of the time it'll be empty. This would |
|---|
| 190 | // waste a lot of memory because of STL allocation policies. |
|---|
| 191 | }; |
|---|
| 192 | |
|---|
| 193 | class Location |
|---|
| 194 | { |
|---|
| 195 | public: |
|---|
| 196 | Location(); |
|---|
| 197 | ~Location(); |
|---|
| 198 | |
|---|
| 199 | void Deserialize(Archive & rArchive); |
|---|
| 200 | void Serialize(Archive & rArchive) const; |
|---|
| 201 | private: |
|---|
| 202 | Location(const Location &); // copy not allowed |
|---|
| 203 | Location &operator=(const Location &); |
|---|
| 204 | public: |
|---|
| 205 | std::string mName; |
|---|
| 206 | std::string mPath; |
|---|
| 207 | std::auto_ptr<BackupClientDirectoryRecord> mpDirectoryRecord; |
|---|
| 208 | int mIDMapIndex; |
|---|
| 209 | ExcludeList *mpExcludeFiles; |
|---|
| 210 | ExcludeList *mpExcludeDirs; |
|---|
| 211 | |
|---|
| 212 | #ifdef ENABLE_VSS |
|---|
| 213 | bool mIsSnapshotCreated; |
|---|
| 214 | VSS_ID mSnapshotVolumeId; |
|---|
| 215 | std::string mSnapshotPath; |
|---|
| 216 | #endif |
|---|
| 217 | }; |
|---|
| 218 | |
|---|
| 219 | #endif // BACKUPCLIENTDIRECTORYRECORD__H |
|---|
| 220 | |
|---|
| 221 | |
|---|