1 // distribution boxbackup-0.11_trunk_2979 (svn version: 2979) 2 // Box Backup, http://www.boxbackup.org/ 3 // 4 // Copyright (c) 2003-2010, Ben Summers and contributors. 5 // All rights reserved. 6 // 7 // Note that this project uses mixed licensing. Any file with this license 8 // attached, or where the code LICENSE-GPL appears on the first line, falls 9 // under the "Box Backup GPL" license. See the file COPYING.txt for more 10 // information about this license. 11 // 12 // --------------------------------------------------------------------- 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of the GNU General Public License 15 // as published by the Free Software Foundation; either version 2 16 // of the License, or (at your option) any later version. 17 // 18 // This program is distributed in the hope that it will be useful, 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 // GNU General Public License for more details. 22 // 23 // You should have received a copy of the GNU General Public License 24 // along with this program; if not, write to the Free Software 25 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 26 // 27 // [http://www.gnu.org/licenses/old-licenses/gpl-2.0.html#SEC4] 28 // 29 // As a special exception to the GPLv2, the Box Backup Project gives 30 // permission to link any code falling under this license (the Box Backup 31 // GPL) with any software that can be downloaded from 32 // the OpenSSL website [http://www.openssl.org] under either the 33 // "OpenSSL License" or the "Original SSLeay License", and to distribute 34 // the linked executables under the terms of the "Box Backup GPL" license. 35 // 36 // As a special exception to the GPLv2, the Box Backup Project gives 37 // permission to link any code falling under this license (the Box Backup 38 // GPL) with any version of Microsoft's Volume Shadow Copy Service 7.2 SDK 39 // or Microsoft Windows Software Development Kit (SDK), including 40 // vssapi.lib, that can be downloaded from the Microsoft website 41 // [*.microsoft.com], and to distribute the linked executables under the 42 // terms of the "Box Backup GPL" license. 43 // -------------------------------------------------------------------------- 44 // 45 // File 46 // Name: BackupClientDirectoryRecord.h 47 // Purpose: Implementation of record about directory for backup client 48 // Created: 2003/10/08 49 // 50 // -------------------------------------------------------------------------- 51 52 #ifndef BACKUPCLIENTDIRECTORYRECORD__H 53 #define BACKUPCLIENTDIRECTORYRECORD__H 54 55 #include <string> 56 #include <map> 57 58 #include "BackupClientFileAttributes.h" 59 #include "BackupDaemonInterface.h" 60 #include "BackupStoreDirectory.h" 61 #include "BoxTime.h" 62 #include "MD5Digest.h" 63 #include "ReadLoggingStream.h" 64 #include "RunStatusProvider.h" 65 66 class Archive; 67 class BackupClientContext; 68 class BackupDaemon; 69 70 // -------------------------------------------------------------------------- 71 // 72 // Class 73 // Name: BackupClientDirectoryRecord 74 // Purpose: Implementation of record about directory for backup client 75 // Created: 2003/10/08 76 // 77 // -------------------------------------------------------------------------- 78 class BackupClientDirectoryRecord 79 { 80 public: 81 BackupClientDirectoryRecord(int64_t ObjectID, const std::string &rSubDirName); 82 ~BackupClientDirectoryRecord(); 83 84 void Deserialize(Archive & rArchive); 85 void Serialize(Archive & rArchive) const; 86 private: 87 BackupClientDirectoryRecord(const BackupClientDirectoryRecord &); 88 public: 89 90 enum 91 { 92 UnknownDirectoryID = 0 93 }; 94 95 // -------------------------------------------------------------------------- 96 // 97 // Class 98 // Name: BackupClientDirectoryRecord::SyncParams 99 // Purpose: Holds parameters etc for directory syncing. Not passed as 100 // const, some parameters may be modified during sync. 101 // Created: 8/3/04 102 // 103 // -------------------------------------------------------------------------- 104 class SyncParams : public ReadLoggingStream::Logger 105 { 106 public: 107 SyncParams( 108 RunStatusProvider &rRunStatusProvider, 109 SysadminNotifier &rSysadminNotifier, 110 ProgressNotifier &rProgressNotifier, 111 BackupClientContext &rContext); 112 ~SyncParams(); 113 private: 114 // No copying 115 SyncParams(const SyncParams&); 116 SyncParams &operator=(const SyncParams&); 117 118 public: 119 // Data members are public, as accessors are not justified here 120 box_time_t mSyncPeriodStart; 121 box_time_t mSyncPeriodEnd; 122 box_time_t mMaxUploadWait; 123 box_time_t mMaxFileTimeInFuture; 124 int32_t mFileTrackingSizeThreshold; 125 int32_t mDiffingUploadSizeThreshold; 126 RunStatusProvider &mrRunStatusProvider; 127 SysadminNotifier &mrSysadminNotifier; 128 ProgressNotifier &mrProgressNotifier; 129 BackupClientContext &mrContext; 130 bool mReadErrorsOnFilesystemObjects; 131 int64_t mMaxUploadRate; 132 133 // Member variables modified by syncing process 134 box_time_t mUploadAfterThisTimeInTheFuture; 135 bool mHaveLoggedWarningAboutFutureFileTimes; 136 StopRun()137 bool StopRun() { return mrRunStatusProvider.StopRun(); } NotifySysadmin(SysadminNotifier::EventCode Event)138 void NotifySysadmin(SysadminNotifier::EventCode Event) 139 { 140 mrSysadminNotifier.NotifySysadmin(Event); 141 } GetProgressNotifier()142 ProgressNotifier& GetProgressNotifier() const 143 { 144 return mrProgressNotifier; 145 } 146 147 /* ReadLoggingStream::Logger implementation */ Log(int64_t readSize,int64_t offset,int64_t length,box_time_t elapsed,box_time_t finish)148 virtual void Log(int64_t readSize, int64_t offset, 149 int64_t length, box_time_t elapsed, box_time_t finish) 150 { 151 mrProgressNotifier.NotifyReadProgress(readSize, offset, 152 length, elapsed, finish); 153 } Log(int64_t readSize,int64_t offset,int64_t length)154 virtual void Log(int64_t readSize, int64_t offset, 155 int64_t length) 156 { 157 mrProgressNotifier.NotifyReadProgress(readSize, offset, 158 length); 159 } Log(int64_t readSize,int64_t offset)160 virtual void Log(int64_t readSize, int64_t offset) 161 { 162 mrProgressNotifier.NotifyReadProgress(readSize, offset); 163 } 164 }; 165 166 void SyncDirectory(SyncParams &rParams, 167 int64_t ContainingDirectoryID, 168 const std::string &rLocalPath, 169 const std::string &rRemotePath, 170 bool ThisDirHasJustBeenCreated = false); 171 172 private: 173 void DeleteSubDirectories(); 174 BackupStoreDirectory *FetchDirectoryListing(SyncParams &rParams); 175 void UpdateAttributes(SyncParams &rParams, 176 BackupStoreDirectory *pDirOnStore, 177 const std::string &rLocalPath); 178 bool UpdateItems(SyncParams &rParams, const std::string &rLocalPath, 179 const std::string &rRemotePath, 180 BackupStoreDirectory *pDirOnStore, 181 std::vector<BackupStoreDirectory::Entry *> &rEntriesLeftOver, 182 std::vector<std::string> &rFiles, 183 const std::vector<std::string> &rDirs); 184 int64_t UploadFile(SyncParams &rParams, 185 const std::string &rFilename, 186 const BackupStoreFilename &rStoreFilename, 187 int64_t FileSize, box_time_t ModificationTime, 188 box_time_t AttributesHash, bool NoPreviousVersionOnServer); 189 void SetErrorWhenReadingFilesystemObject(SyncParams &rParams, 190 const char *Filename); 191 void RemoveDirectoryInPlaceOfFile(SyncParams &rParams, 192 BackupStoreDirectory* pDirOnStore, 193 BackupStoreDirectory::Entry* pEntry, 194 const std::string &rFilename); 195 196 private: 197 int64_t mObjectID; 198 std::string mSubDirName; 199 bool mInitialSyncDone; 200 bool mSyncDone; 201 bool mSuppressMultipleLinksWarning; 202 203 // Checksum of directory contents and attributes, used to detect changes 204 uint8_t mStateChecksum[MD5Digest::DigestLength]; 205 206 std::map<std::string, box_time_t> *mpPendingEntries; 207 std::map<std::string, BackupClientDirectoryRecord *> mSubDirectories; 208 // mpPendingEntries is a pointer rather than simple a member 209 // variable, because most of the time it'll be empty. This would 210 // waste a lot of memory because of STL allocation policies. 211 }; 212 213 #endif // BACKUPCLIENTDIRECTORYRECORD__H 214 215 216