Ignore:
Timestamp:
28/05/2008 16:24:05 (4 years ago)
Author:
chris
Message:

Track and log file deletions by name.

Split crypto init and file sync process into its own method, to reduce
call depth and facilitate calling in process from tests.

Differentiate between 3 uses of stat in BackupClientDirectoryRecord? by
renaming the structures.

Use stat instead of lstat when checking the filesystem that's holding an
entity, in case it's a symbolic link to a different filesystem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp

    r2143 r2181  
    33// File 
    44//              Name:    BackupClientDirectoryRecord.cpp 
    5 //              Purpose: Implementation of record about directory for backup client 
     5//              Purpose: Implementation of record about directory for 
     6//                       backup client 
    67//              Created: 2003/10/08 
    78// 
     
    101102// 
    102103// Function 
    103 //              Name:    BackupClientDirectoryRecord::SyncDirectory(BackupClientDirectoryRecord::SyncParams &, int64_t, const std::string &, bool) 
    104 //              Purpose: Syncronise, recusively, a local directory with the server. 
     104//              Name:    BackupClientDirectoryRecord::SyncDirectory(i 
     105//                       BackupClientDirectoryRecord::SyncParams &, 
     106//                       int64_t, const std::string &, 
     107//                       const std::string &, bool) 
     108//              Purpose: Recursively synchronise a local directory 
     109//                       with the server. 
    105110//              Created: 2003/10/08 
    106111// 
    107112// -------------------------------------------------------------------------- 
    108 void BackupClientDirectoryRecord::SyncDirectory(BackupClientDirectoryRecord::SyncParams &rParams, int64_t ContainingDirectoryID, 
    109         const std::string &rLocalPath, bool ThisDirHasJustBeenCreated) 
     113void BackupClientDirectoryRecord::SyncDirectory( 
     114        BackupClientDirectoryRecord::SyncParams &rParams, 
     115        int64_t ContainingDirectoryID, 
     116        const std::string &rLocalPath, 
     117        const std::string &rRemotePath, 
     118        bool ThisDirHasJustBeenCreated) 
    110119{ 
     120        BackupClientContext& rContext(rParams.mrContext); 
     121        ProgressNotifier& rNotifier(rContext.GetProgressNotifier()); 
     122 
    111123        // Signal received by daemon? 
    112124        if(rParams.mrDaemon.StopRun()) 
     
    119131        // and on the immediate sub directories. 
    120132        mSyncDone = false; 
    121         for(std::map<std::string, BackupClientDirectoryRecord *>::iterator i = mSubDirectories.begin(); 
     133        for(std::map<std::string, BackupClientDirectoryRecord *>::iterator 
     134                i  = mSubDirectories.begin(); 
    122135                i != mSubDirectories.end(); ++i) 
    123136        { 
     
    125138        } 
    126139 
    127         // Work out the time in the future after which the file should be uploaded regardless. 
    128         // This is a simple way to avoid having too many problems with file servers when they have 
    129         // clients with badly out of sync clocks. 
    130         rParams.mUploadAfterThisTimeInTheFuture = GetCurrentBoxTime() + rParams.mMaxFileTimeInFuture; 
    131          
    132         // Build the current state checksum to compare against while getting info from dirs 
    133         // Note checksum is used locally only, so byte order isn't considered. 
     140        // Work out the time in the future after which the file should 
     141        // be uploaded regardless. This is a simple way to avoid having 
     142        // too many problems with file servers when they have clients 
     143        // with badly out of sync clocks. 
     144        rParams.mUploadAfterThisTimeInTheFuture = GetCurrentBoxTime() + 
     145                rParams.mMaxFileTimeInFuture; 
     146         
     147        // Build the current state checksum to compare against while 
     148        // getting info from dirs. Note checksum is used locally only, 
     149        // so byte order isn't considered. 
    134150        MD5Digest currentStateChecksum; 
    135151         
     152        struct stat dest_st; 
    136153        // Stat the directory, to get attribute info 
    137         { 
    138                 struct stat st; 
    139                 if(::stat(rLocalPath.c_str(), &st) != 0) 
    140                 { 
    141                         // The directory has probably been deleted, so just ignore this error. 
    142                         // In a future scan, this deletion will be noticed, deleted from server, and this object deleted. 
    143                         rParams.GetProgressNotifier().NotifyDirStatFailed( 
    144                                 this, rLocalPath, strerror(errno)); 
     154        // If it's a symbolic link, we want the link target here 
     155        // (as we're about to back up the contents of the directory) 
     156        { 
     157                if(::stat(rLocalPath.c_str(), &dest_st) != 0) 
     158                { 
     159                        // The directory has probably been deleted, so 
     160                        // just ignore this error. In a future scan, this 
     161                        // deletion will be noticed, deleted from server, 
     162                        // and this object deleted. 
     163                        rNotifier.NotifyDirStatFailed(this, rLocalPath, 
     164                                strerror(errno)); 
    145165                        return; 
    146166                } 
    147                 // Store inode number in map so directories are tracked in case they're renamed 
    148                 { 
    149                         BackupClientInodeToIDMap &idMap(rParams.mrContext.GetNewIDMap()); 
    150                         idMap.AddToMap(st.st_ino, mObjectID, ContainingDirectoryID); 
     167                // Store inode number in map so directories are tracked 
     168                // in case they're renamed 
     169                { 
     170                        BackupClientInodeToIDMap &idMap( 
     171                                rParams.mrContext.GetNewIDMap()); 
     172                        idMap.AddToMap(dest_st.st_ino, mObjectID, 
     173                                ContainingDirectoryID); 
    151174                } 
    152175                // Add attributes to checksum 
    153                 currentStateChecksum.Add(&st.st_mode, sizeof(st.st_mode)); 
    154                 currentStateChecksum.Add(&st.st_uid, sizeof(st.st_uid)); 
    155                 currentStateChecksum.Add(&st.st_gid, sizeof(st.st_gid)); 
     176                currentStateChecksum.Add(&dest_st.st_mode, 
     177                        sizeof(dest_st.st_mode)); 
     178                currentStateChecksum.Add(&dest_st.st_uid, 
     179                        sizeof(dest_st.st_uid)); 
     180                currentStateChecksum.Add(&dest_st.st_gid, 
     181                        sizeof(dest_st.st_gid)); 
    156182                // Inode to be paranoid about things moving around 
    157                 currentStateChecksum.Add(&st.st_ino, sizeof(st.st_ino)); 
     183                currentStateChecksum.Add(&dest_st.st_ino, 
     184                        sizeof(dest_st.st_ino)); 
    158185#ifdef HAVE_STRUCT_STAT_ST_FLAGS 
    159                 currentStateChecksum.Add(&st.st_flags, sizeof(st.st_flags)); 
     186                currentStateChecksum.Add(&dest_st.st_flags, 
     187                        sizeof(dest_st.st_flags)); 
    160188#endif 
    161189 
    162190                StreamableMemBlock xattr; 
    163                 BackupClientFileAttributes::FillExtendedAttr(xattr, rLocalPath.c_str()); 
     191                BackupClientFileAttributes::FillExtendedAttr(xattr, 
     192                        rLocalPath.c_str()); 
    164193                currentStateChecksum.Add(xattr.GetBuffer(), xattr.GetSize()); 
    165194        } 
     
    171200        bool downloadDirectoryRecordBecauseOfFutureFiles = false; 
    172201 
    173         struct stat dir_st; 
    174         if(::lstat(rLocalPath.c_str(), &dir_st) != 0) 
     202        struct stat link_st; 
     203        if(::lstat(rLocalPath.c_str(), &link_st) != 0) 
    175204        { 
    176205                // Report the error (logs and  
    177206                // eventual email to administrator) 
    178                 rParams.GetProgressNotifier().NotifyFileStatFailed(this,  
    179                         rLocalPath, strerror(errno)); 
     207                rNotifier.NotifyFileStatFailed(this, rLocalPath, 
     208                        strerror(errno)); 
    180209                 
    181210                // FIXME move to NotifyFileStatFailed() 
     
    193222                try 
    194223                { 
    195                         rParams.GetProgressNotifier().NotifyScanDirectory( 
    196                                 this, rLocalPath); 
     224                        rNotifier.NotifyScanDirectory(this, rLocalPath); 
    197225 
    198226                        dirHandle = ::opendir(rLocalPath.c_str()); 
     
    203231                                if (errno == EACCES) 
    204232                                { 
    205                                         rParams.GetProgressNotifier().NotifyDirListFailed( 
    206                                                 this, rLocalPath, "Access denied"); 
     233                                        rNotifier.NotifyDirListFailed(this, 
     234                                                rLocalPath, "Access denied"); 
    207235                                } 
    208236                                else 
    209237                                { 
    210                                         rParams.GetProgressNotifier().NotifyDirListFailed(this,  
     238                                        rNotifier.NotifyDirListFailed(this,  
    211239                                                rLocalPath, strerror(errno)); 
    212240                                } 
    213241                                 
    214                                 // Report the error (logs and eventual email to administrator) 
    215                                 SetErrorWhenReadingFilesystemObject(rParams, rLocalPath.c_str()); 
     242                                // Report the error (logs and eventual email 
     243                                // to administrator) 
     244                                SetErrorWhenReadingFilesystemObject(rParams, 
     245                                        rLocalPath.c_str()); 
    216246                                // Ignore this directory for now. 
    217247                                return; 
     
    229259         
    230260                        struct dirent *en = 0; 
    231                         struct stat st; 
     261                        struct stat file_st; 
    232262                        std::string filename; 
    233263                        while((en = ::readdir(dirHandle)) != 0) 
     
    235265                                rParams.mrContext.DoKeepAlive(); 
    236266                                 
    237                                 // Don't need to use LinuxWorkaround_FinishDirentStruct(en, rLocalPath.c_str()); 
    238                                 // on Linux, as a stat is performed to get all this info 
     267                                // Don't need to use 
     268                                // LinuxWorkaround_FinishDirentStruct(en, 
     269                                // rLocalPath.c_str()); 
     270                                // on Linux, as a stat is performed to 
     271                                // get all this info 
    239272 
    240273                                if(en->d_name[0] == '.' &&  
     
    260293                                int type = en->d_type; 
    261294                                #else 
    262                                 if(::lstat(filename.c_str(), &st) != 0) 
     295                                if(::lstat(filename.c_str(), &file_st) != 0) 
    263296                                { 
    264297                                        // Report the error (logs and  
    265298                                        // eventual email to administrator) 
    266                                         rParams.GetProgressNotifier().NotifyFileStatFailed(this,  
     299                                        rNotifier.NotifyFileStatFailed(this,  
    267300                                                filename, strerror(errno)); 
    268301                                         
     
    275308                                } 
    276309 
    277                                 if(st.st_dev != dir_st.st_dev) 
     310                                if(file_st.st_dev != dest_st.st_dev) 
    278311                                { 
    279312                                        if(!(rParams.mrContext.ExcludeDir( 
    280313                                                filename))) 
    281314                                        { 
    282                                                 rParams.GetProgressNotifier() 
    283                                                         .NotifyMountPointSkipped( 
    284                                                                 this, filename); 
     315                                                rNotifier.NotifyMountPointSkipped( 
     316                                                        this, filename); 
    285317                                        } 
    286318                                        continue; 
    287319                                } 
    288320 
    289                                 int type = st.st_mode & S_IFMT; 
     321                                int type = file_st.st_mode & S_IFMT; 
    290322                                #endif 
    291323 
     
    297329                                        if(rParams.mrContext.ExcludeFile(filename)) 
    298330                                        { 
    299                                                 rParams.GetProgressNotifier() 
    300                                                         .NotifyFileExcluded( 
     331                                                rNotifier.NotifyFileExcluded( 
    301332                                                                this,  
    302333                                                                filename); 
     
    316347                                        if(rParams.mrContext.ExcludeDir(filename)) 
    317348                                        { 
    318                                                 rParams.GetProgressNotifier() 
    319                                                         .NotifyDirExcluded( 
     349                                                rNotifier.NotifyDirExcluded( 
    320350                                                                this,  
    321351                                                                filename); 
     
    332362                                        if(rParams.mrContext.ExcludeFile(filename)) 
    333363                                        { 
    334                                                 rParams.GetProgressNotifier() 
    335                                                         .NotifyFileExcluded( 
     364                                                rNotifier.NotifyFileExcluded( 
    336365                                                                this,  
    337366                                                                filename); 
     
    339368                                        else 
    340369                                        { 
    341                                                 rParams.GetProgressNotifier() 
    342                                                         .NotifyUnsupportedFileType( 
     370                                                rNotifier.NotifyUnsupportedFileType( 
    343371                                                                this, filename); 
    344372                                                SetErrorWhenReadingFilesystemObject( 
     
    355383                                // We didn't stat the file before, 
    356384                                // but now we need the information. 
    357                                 if(::lstat(filename.c_str(), &st) != 0) 
    358                                 { 
    359                                         rParams.GetProgressNotifier() 
    360                                                 .NotifyFileStatFailed(this,  
     385                                if(::lstat(filename.c_str(), &file_st) != 0) 
     386                                { 
     387                                        rNotifier.NotifyFileStatFailed(this,  
    361388                                                        filename,  
    362389                                                        strerror(errno)); 
     
    371398                                } 
    372399 
    373                                 if(st.st_dev != dir_st.st_dev) 
    374                                 { 
    375                                         rParams.GetProgressNotifier() 
    376                                                 .NotifyMountPointSkipped(this,  
     400                                if(file_st.st_dev != link_st.st_dev) 
     401                                { 
     402                                        rNotifier.NotifyMountPointSkipped(this,  
    377403                                                        filename); 
    378404                                        continue; 
     
    380406                                #endif 
    381407 
    382                                 checksum_info.mModificationTime = FileModificationTime(st); 
    383                                 checksum_info.mAttributeModificationTime = FileAttrModificationTime(st); 
    384                                 checksum_info.mSize = st.st_size; 
     408                                checksum_info.mModificationTime = FileModificationTime(file_st); 
     409                                checksum_info.mAttributeModificationTime = FileAttrModificationTime(file_st); 
     410                                checksum_info.mSize = file_st.st_size; 
    385411                                currentStateChecksum.Add(&checksum_info, sizeof(checksum_info)); 
    386412                                currentStateChecksum.Add(en->d_name, strlen(en->d_name)); 
     
    395421                                        if(!rParams.mHaveLoggedWarningAboutFutureFileTimes) 
    396422                                        { 
    397                                                 rParams.GetProgressNotifier().NotifyFileModifiedInFuture( 
     423                                                rNotifier.NotifyFileModifiedInFuture( 
    398424                                                        this, filename); 
    399425                                                rParams.mHaveLoggedWarningAboutFutureFileTimes = true; 
     
    469495                 
    470496                // Do the directory reading 
    471                 bool updateCompleteSuccess = UpdateItems(rParams, rLocalPath, pdirOnStore, entriesLeftOver, files, dirs); 
     497                bool updateCompleteSuccess = UpdateItems(rParams, rLocalPath, 
     498                        rRemotePath, pdirOnStore, entriesLeftOver, files, dirs); 
    472499                 
    473500                // LAST THING! (think exception safety) 
     
    605632// 
    606633// -------------------------------------------------------------------------- 
    607 bool BackupClientDirectoryRecord::UpdateItems(BackupClientDirectoryRecord::SyncParams &rParams, 
    608         const std::string &rLocalPath, BackupStoreDirectory *pDirOnStore, 
     634bool BackupClientDirectoryRecord::UpdateItems( 
     635        BackupClientDirectoryRecord::SyncParams &rParams, 
     636        const std::string &rLocalPath, 
     637        const std::string &rRemotePath, 
     638        BackupStoreDirectory *pDirOnStore, 
    609639        std::vector<BackupStoreDirectory::Entry *> &rEntriesLeftOver, 
    610         std::vector<std::string> &rFiles, const std::vector<std::string> &rDirs) 
     640        std::vector<std::string> &rFiles, 
     641        const std::vector<std::string> &rDirs) 
    611642{ 
     643        BackupClientContext& rContext(rParams.mrContext); 
     644        ProgressNotifier& rNotifier(rContext.GetProgressNotifier()); 
     645 
    612646        bool allUpdatedSuccessfully = true; 
    613647 
     
    635669        { 
    636670                // Send keep-alive message if needed 
    637                 rParams.mrContext.DoKeepAlive(); 
     671                rContext.DoKeepAlive(); 
    638672                 
    639673                // Filename of this file 
     
    652686                        if(::lstat(filename.c_str(), &st) != 0) 
    653687                        { 
    654                                 rParams.GetProgressNotifier().NotifyFileStatFailed(this,  
     688                                rNotifier.NotifyFileStatFailed(this,  
    655689                                        filename, strerror(errno)); 
    656690 
     
    690724                { 
    691725                        // Directory exists in the place of this file -- sort it out 
    692                         RemoveDirectoryInPlaceOfFile(rParams, pDirOnStore, en->GetObjectID(), *f); 
     726                        RemoveDirectoryInPlaceOfFile(rParams, pDirOnStore, 
     727                                en, *f); 
    693728                        en = 0; 
    694729                } 
     
    702737                         
    703738                        // Do we know about the inode number? 
    704                         const BackupClientInodeToIDMap &idMap(rParams.mrContext.GetCurrentIDMap()); 
     739                        const BackupClientInodeToIDMap &idMap(rContext.GetCurrentIDMap()); 
    705740                        int64_t renameObjectID = 0, renameInDirectory = 0; 
    706741                        if(idMap.Lookup(inodeNum, renameObjectID, renameInDirectory)) 
     
    712747                                box_time_t srvModTime = 0, srvAttributesHash = 0; 
    713748                                BackupStoreFilenameClear oldLeafname; 
    714                                 if(rParams.mrContext.FindFilename(renameObjectID, renameInDirectory, localPotentialOldName, isDir, isCurrentVersion, &srvModTime, &srvAttributesHash, &oldLeafname)) 
     749                                if(rContext.FindFilename(renameObjectID, renameInDirectory, localPotentialOldName, isDir, isCurrentVersion, &srvModTime, &srvAttributesHash, &oldLeafname)) 
    715750                                {        
    716751                                        // Only interested if it's a file and the latest version 
     
    725760 
    726761                                                        // Get the connection to the server  
    727                                                         BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
     762                                                        BackupProtocolClient &connection(rContext.GetConnection()); 
    728763 
    729764                                                        // Only do this step if there is room on the server. 
    730765                                                        // This step will be repeated later when there is space available 
    731                                                         if(!rParams.mrContext.StorageLimitExceeded()) 
     766                                                        if(!rContext.StorageLimitExceeded()) 
    732767                                                        { 
    733768                                                                // Rename the existing files (ie include old versions) on the server 
     
    737772                                                                         
    738773                                                                // Stop the attempt to delete the file in the original location 
    739                                                                 BackupClientDeleteList &rdelList(rParams.mrContext.GetDeleteList()); 
     774                                                                BackupClientDeleteList &rdelList(rContext.GetDeleteList()); 
    740775                                                                rdelList.StopFileDeletion(renameInDirectory, oldLeafname); 
    741776                                                                 
     
    872907                } 
    873908 
     909                bool fileSynced = true; 
     910 
    874911                if (doUpload) 
    875912                { 
     913                        // Upload needed, don't mark sync success until 
     914                        // we've actually done it 
     915                        fileSynced = false; 
     916 
    876917                        // Make sure we're connected -- must connect here so we know whether 
    877918                        // the storage limit has been exceeded, and hence whether or not 
    878919                        // to actually upload the file. 
    879                         rParams.mrContext.GetConnection(); 
     920                        rContext.GetConnection(); 
    880921 
    881922                        // Only do this step if there is room on the server. 
    882923                        // This step will be repeated later when there is space available 
    883                         if(!rParams.mrContext.StorageLimitExceeded()) 
     924                        if(!rContext.StorageLimitExceeded()) 
    884925                        { 
    885926                                // Upload the file to the server, recording the object ID it returns 
     
    891932                                { 
    892933                                        latestObjectID = UploadFile(rParams, filename, storeFilename, fileSize, modTime, attributesHash, noPreviousVersionOnServer); 
    893                                         uploadSuccess = true; 
     934                                        if (latestObjectID == 0) 
     935                                        { 
     936                                                // storage limit exceeded 
     937                                                rParams.mrContext.SetStorageLimitExceeded(); 
     938                                                uploadSuccess = false; 
     939                                                allUpdatedSuccessfully = false; 
     940                                        } 
     941                                        else 
     942                                        { 
     943                                                uploadSuccess = true; 
     944                                        } 
    894945                                } 
    895946                                catch(ConnectionException &e) 
     
    897948                                        // Connection errors should just be passed on to the main handler, retries 
    898949                                        // would probably just cause more problems. 
    899                                         rParams.GetProgressNotifier() 
    900                                                 .NotifyFileUploadException( 
    901                                                         this, filename, e); 
     950                                        // StorageLimitExceeded never gets here. 
     951                                         
     952                                        rParams.mrDaemon.NotifySysadmin(BackupDaemon::NotifyEvent_StoreFull); 
     953                                        rNotifier.NotifyFileUploadException( 
     954                                                this, filename, e); 
    902955                                        throw; 
    903956                                } 
     
    908961                                        // Log it. 
    909962                                        SetErrorWhenReadingFilesystemObject(rParams, filename.c_str()); 
    910                                         rParams.GetProgressNotifier() 
    911                                                 .NotifyFileUploadException( 
    912                                                         this, filename, e); 
     963                                        rNotifier.NotifyFileUploadException( 
     964                                                this, filename, e); 
    913965                                } 
    914966 
     
    916968                                if(uploadSuccess) 
    917969                                { 
     970                                        fileSynced = true; 
     971 
    918972                                        // delete from pending entries 
    919973                                        if(pendingFirstSeenTime != 0 && mpPendingEntries != 0) 
     
    925979                        else 
    926980                        { 
    927                                 rParams.GetProgressNotifier().NotifyFileSkippedServerFull(this, 
     981                                rNotifier.NotifyFileSkippedServerFull(this, 
    928982                                        filename); 
    929983                        } 
     
    932986                { 
    933987                        // Attributes have probably changed, upload them again. 
    934                         // If the attributes have changed enough, the directory hash will have changed too, 
    935                         // and so the dir will have been downloaded, and the entry will be available. 
     988                        // If the attributes have changed enough, the directory 
     989                        // hash will have changed too, and so the dir will have 
     990                        // been downloaded, and the entry will be available. 
    936991 
    937992                        // Get connection 
    938                         BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
     993                        BackupProtocolClient &connection(rContext.GetConnection()); 
    939994 
    940995                        // Only do this step if there is room on the server. 
    941                         // This step will be repeated later when there is space available 
    942                         if(!rParams.mrContext.StorageLimitExceeded()) 
     996                        // This step will be repeated later when there is 
     997                        // space available 
     998                        if(!rContext.StorageLimitExceeded()) 
    943999                        { 
    9441000                                // Update store 
     
    9471003                                MemBlockStream attrStream(attr); 
    9481004                                connection.QuerySetReplacementFileAttributes(mObjectID, attributesHash, storeFilename, attrStream); 
     1005                                fileSynced = true; 
    9491006                        } 
    9501007                } 
     
    9821039                { 
    9831040                        // Get the map 
    984                         BackupClientInodeToIDMap &idMap(rParams.mrContext.GetNewIDMap()); 
     1041                        BackupClientInodeToIDMap &idMap(rContext.GetNewIDMap()); 
    9851042                 
    9861043                        // Need to get an ID from somewhere... 
     
    9941051                                // Don't know it -- haven't sent anything to the store, and didn't get a listing. 
    9951052                                // Look it up in the current map, and if it's there, use that. 
    996                                 const BackupClientInodeToIDMap &currentIDMap(rParams.mrContext.GetCurrentIDMap()); 
     1053                                const BackupClientInodeToIDMap &currentIDMap(rContext.GetCurrentIDMap()); 
    9971054                                int64_t objid = 0, dirid = 0; 
    9981055                                if(currentIDMap.Lookup(inodeNum, objid, dirid)) 
     
    10031060                                        // or there is a problem somewhere. If this happened on a short test run, look 
    10041061                                        // into it. However, in a long running process this may happen occasionally and 
    1005                                         // not indiciate anything wrong. 
     1062                                        // not indicate anything wrong. 
    10061063                                        // Run the release version for real life use, where this check is not made. 
    10071064                                        idMap.AddToMap(inodeNum, objid, mObjectID /* containing directory */);                           
     
    10101067                } 
    10111068                 
    1012                 rParams.GetProgressNotifier().NotifyFileSynchronised(this,  
    1013                         filename, fileSize); 
     1069                if (fileSynced) 
     1070                { 
     1071                        rNotifier.NotifyFileSynchronised(this, filename, 
     1072                                fileSize); 
     1073                } 
    10141074        } 
    10151075 
     
    10311091        { 
    10321092                // Send keep-alive message if needed 
    1033                 rParams.mrContext.DoKeepAlive(); 
     1093                rContext.DoKeepAlive(); 
    10341094                 
    10351095                // Get the local filename 
     
    10511111                if((en != 0) && ((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) == 0)) 
    10521112                { 
    1053                         // Entry exists, but is not a directory. Bad. Get rid of it. 
    1054                         BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
     1113                        // Entry exists, but is not a directory. Bad. 
     1114                        // Get rid of it. 
     1115                        BackupProtocolClient &connection(rContext.GetConnection()); 
    10551116                        connection.QueryDeleteFile(mObjectID /* in directory */, storeFilename); 
     1117                        rNotifier.NotifyFileDeleted(en->GetObjectID(), 
     1118                                storeFilename.GetClearFilename()); 
    10561119                         
    10571120                        // Nothing found 
     
    10591122                } 
    10601123 
    1061                 // Flag for having created directory, so can optimise the recusive call not to 
    1062                 // read it again, because we know it's empty. 
     1124                // Flag for having created directory, so can optimise the 
     1125                // recusive call not to read it again, because we know 
     1126                // it's empty. 
    10631127                bool haveJustCreatedDirOnServer = false; 
    10641128 
     
    10871151                                subDirObjectID = en->GetObjectID(); 
    10881152                        } 
    1089                         else if(rParams.mrContext.StorageLimitExceeded())        
     1153                        else if(rContext.StorageLimitExceeded())         
    10901154                        // know we've got a connection if we get this far, 
    10911155                        // as dir will have been modified. 
     
    11131177                                int64_t renameObjectID = 0, renameInDirectory = 0; 
    11141178                                bool renameDir = false; 
    1115                                 const BackupClientInodeToIDMap &idMap(rParams.mrContext.GetCurrentIDMap()); 
     1179                                const BackupClientInodeToIDMap &idMap( 
     1180                                        rContext.GetCurrentIDMap()); 
    11161181                                if(idMap.Lookup(inodeNum, renameObjectID, renameInDirectory)) 
    11171182                                { 
     
    11201185                                        bool isDir = false; 
    11211186                                        bool isCurrentVersion = false; 
    1122                                         if(rParams.mrContext.FindFilename(renameObjectID, renameInDirectory, localPotentialOldName, isDir, isCurrentVersion)) 
     1187                                        if(rContext.FindFilename(renameObjectID, renameInDirectory, localPotentialOldName, isDir, isCurrentVersion)) 
    11231188                                        {        
    11241189                                                // Only interested if it's a directory 
     
    11381203 
    11391204                                // Get connection 
    1140                                 BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
     1205                                BackupProtocolClient &connection(rContext.GetConnection()); 
    11411206                                 
    11421207                                // Don't do a check for storage limit exceeded here, because if we get to this 
     
    11581223 
    11591224                                        // Stop it being deleted later 
    1160                                         BackupClientDeleteList &rdelList(rParams.mrContext.GetDeleteList()); 
     1225                                        BackupClientDeleteList &rdelList( 
     1226                                                rContext.GetDeleteList()); 
    11611227                                        rdelList.StopDirectoryDeletion(renameObjectID); 
    11621228 
     
    11951261                } 
    11961262                 
    1197                 ASSERT(psubDirRecord != 0 || rParams.mrContext.StorageLimitExceeded()); 
     1263                ASSERT(psubDirRecord != 0 || rContext.StorageLimitExceeded()); 
    11981264                 
    11991265                if(psubDirRecord) 
    12001266                { 
    12011267                        // Sync this sub directory too 
    1202                         psubDirRecord->SyncDirectory(rParams, mObjectID, dirname, haveJustCreatedDirOnServer); 
     1268                        psubDirRecord->SyncDirectory(rParams, mObjectID, 
     1269                                dirname, rRemotePath + "/" + *d, 
     1270                                haveJustCreatedDirOnServer); 
    12031271                } 
    12041272 
     
    12291297                        // If there's an error during the process, it doesn't matter if things 
    12301298                        // aren't actually deleted, as the whole state will be reset anyway. 
    1231                         BackupClientDeleteList &rdel(rParams.mrContext.GetDeleteList()); 
     1299                        BackupClientDeleteList &rdel(rContext.GetDeleteList()); 
     1300 
     1301                        std::string localName = MakeFullPath(rLocalPath, 
     1302                                en->GetName()); 
    12321303                         
    12331304                        // Delete this entry -- file or directory? 
     
    12351306                        { 
    12361307                                // Set a pending deletion for the file 
    1237                                 rdel.AddFileDelete(mObjectID, en->GetName());                            
     1308                                rdel.AddFileDelete(mObjectID, en->GetName(), 
     1309                                        localName); 
    12381310                        } 
    12391311                        else if((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) != 0) 
    12401312                        { 
    12411313                                // Set as a pending deletion for the directory 
    1242                                 rdel.AddDirectoryDelete(en->GetObjectID()); 
     1314                                rdel.AddDirectoryDelete(en->GetObjectID(), 
     1315                                        localName); 
    12431316                                 
    1244                                 // If there's a directory record for it in the sub directory map, delete it now 
     1317                                // If there's a directory record for it in  
     1318                                // the sub directory map, delete it now 
    12451319                                BackupStoreFilenameClear dirname(en->GetName()); 
    12461320                                std::map<std::string, BackupClientDirectoryRecord *>::iterator e(mSubDirectories.find(dirname.GetClearFilename())); 
     
    12771351// 
    12781352// -------------------------------------------------------------------------- 
    1279 void BackupClientDirectoryRecord::RemoveDirectoryInPlaceOfFile(SyncParams &rParams, BackupStoreDirectory *pDirOnStore, int64_t ObjectID, const std::string &rFilename) 
     1353void BackupClientDirectoryRecord::RemoveDirectoryInPlaceOfFile( 
     1354        SyncParams &rParams, 
     1355        BackupStoreDirectory* pDirOnStore, 
     1356        BackupStoreDirectory::Entry* pEntry, 
     1357        const std::string &rFilename) 
    12801358{ 
    12811359        // First, delete the directory 
    12821360        BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
    1283         connection.QueryDeleteDirectory(ObjectID); 
     1361        connection.QueryDeleteDirectory(pEntry->GetObjectID()); 
     1362 
     1363        BackupStoreFilenameClear clear(pEntry->GetName()); 
     1364        rParams.mrContext.GetProgressNotifier().NotifyDirectoryDeleted( 
     1365                pEntry->GetObjectID(), clear.GetClearFilename()); 
    12841366 
    12851367        // Then, delete any directory record 
    1286         std::map<std::string, BackupClientDirectoryRecord *>::iterator e(mSubDirectories.find(rFilename)); 
     1368        std::map<std::string, BackupClientDirectoryRecord *>::iterator 
     1369                e(mSubDirectories.find(rFilename)); 
     1370 
    12871371        if(e != mSubDirectories.end()) 
    12881372        { 
     
    13011385// 
    13021386// Function 
    1303 //              Name:    BackupClientDirectoryRecord::UploadFile(BackupClientDirectoryRecord::SyncParams &, const std::string &, const BackupStoreFilename &, int64_t, box_time_t, box_time_t, bool) 
    1304 //              Purpose: Private. Upload a file to the server -- may send a patch instead of the whole thing 
     1387//              Name:    BackupClientDirectoryRecord::UploadFile( 
     1388//                       BackupClientDirectoryRecord::SyncParams &, 
     1389//                       const std::string &, 
     1390//                       const BackupStoreFilename &, 
     1391//                       int64_t, box_time_t, box_time_t, bool) 
     1392//              Purpose: Private. Upload a file to the server. May send 
     1393//                       a patch instead of the whole thing 
    13051394//              Created: 20/1/04 
    13061395// 
    13071396// -------------------------------------------------------------------------- 
    1308 int64_t BackupClientDirectoryRecord::UploadFile(BackupClientDirectoryRecord::SyncParams &rParams, const std::string &rFilename, const BackupStoreFilename &rStoreFilename, 
    1309                         int64_t FileSize, box_time_t ModificationTime, box_time_t AttributesHash, bool NoPreviousVersionOnServer) 
     1397int64_t BackupClientDirectoryRecord::UploadFile( 
     1398        BackupClientDirectoryRecord::SyncParams &rParams, 
     1399        const std::string &rFilename, 
     1400        const BackupStoreFilename &rStoreFilename, 
     1401        int64_t FileSize, 
     1402        box_time_t ModificationTime, 
     1403        box_time_t AttributesHash, 
     1404        bool NoPreviousVersionOnServer) 
    13101405{ 
     1406        BackupClientContext& rContext(rParams.mrContext); 
     1407        ProgressNotifier& rNotifier(rContext.GetProgressNotifier()); 
     1408 
    13111409        // Get the connection 
    1312         BackupProtocolClient &connection(rParams.mrContext.GetConnection()); 
     1410        BackupProtocolClient &connection(rContext.GetConnection()); 
    13131411 
    13141412        // Info 
     
    13191417        try 
    13201418        { 
    1321                 // Might an old version be on the server, and is the file size over the diffing threshold? 
    1322                 if(!NoPreviousVersionOnServer && FileSize >= rParams.mDiffingUploadSizeThreshold) 
     1419                // Might an old version be on the server, and is the file 
     1420                // size over the diffing threshold? 
     1421                if(!NoPreviousVersionOnServer && 
     1422                        FileSize >= rParams.mDiffingUploadSizeThreshold) 
    13231423                { 
    13241424                        // YES -- try to do diff, if possible 
     
    13301430                        { 
    13311431                                // Found an old version 
    1332                                 rParams.GetProgressNotifier().NotifyFileUploadingPatch(this,  
     1432                                rNotifier.NotifyFileUploadingPatch(this,  
    13331433                                        rFilename); 
    13341434 
     
    13401440                                // 
    13411441 
    1342                                 rParams.mrContext.ManageDiffProcess(); 
     1442                                rContext.ManageDiffProcess(); 
    13431443 
    13441444                                bool isCompletelyDifferent = false; 
     
    13491449                                                rStoreFilename, diffFromID, *blockIndexStream, 
    13501450                                                connection.GetTimeout(),  
    1351                                                 &rParams.mrContext, // DiffTimer implementation 
     1451                                                &rContext, // DiffTimer implementation 
    13521452                                                0 /* not interested in the modification time */,  
    13531453                                                &isCompletelyDifferent)); 
    13541454         
    1355                                 rParams.mrContext.UnManageDiffProcess(); 
     1455                                rContext.UnManageDiffProcess(); 
    13561456 
    13571457                                // 
     
    13611461                                                AttributesHash, isCompletelyDifferent?(0):(diffFromID), rStoreFilename, *patchStream)); 
    13621462                                 
     1463                                // Get object ID from the result                 
     1464                                objID = stored->GetObjectID(); 
     1465 
    13631466                                // Don't attempt to upload it again! 
    13641467                                doNormalUpload = false; 
     
    13691472                { 
    13701473                        // below threshold or nothing to diff from, so upload whole 
    1371                         rParams.GetProgressNotifier().NotifyFileUploading(this,  
    1372                                 rFilename); 
     1474                        rNotifier.NotifyFileUploading(this, rFilename); 
    13731475                         
    13741476                        // Prepare to upload, getting a stream which will encode the file as we go along 
     
    13911493        catch(BoxException &e) 
    13921494        { 
    1393                 rParams.mrContext.UnManageDiffProcess(); 
     1495                rContext.UnManageDiffProcess(); 
    13941496 
    13951497                if(e.GetType() == ConnectionException::ExceptionType && e.GetSubType() == ConnectionException::Protocol_UnexpectedReply) 
     
    14051507                                        // The hard limit was exceeded on the server, notify! 
    14061508                                        rParams.mrDaemon.NotifySysadmin(BackupDaemon::NotifyEvent_StoreFull); 
    1407                                 } 
    1408                                 rParams.GetProgressNotifier() 
    1409                                         .NotifyFileUploadServerError( 
    1410                                                 this, rFilename, type, subtype); 
     1509                                        // return an error code instead of 
     1510                                        // throwing an exception that we 
     1511                                        // can't debug. 
     1512                                        return 0; 
     1513                                } 
     1514                                rNotifier.NotifyFileUploadServerError(this, 
     1515                                        rFilename, type, subtype); 
    14111516                        } 
    14121517                } 
     
    14161521        } 
    14171522 
    1418         rParams.GetProgressNotifier().NotifyFileUploaded(this, rFilename, FileSize); 
     1523        rNotifier.NotifyFileUploaded(this, rFilename, FileSize); 
    14191524 
    14201525        // Return the new object ID of this file 
     
    14581563// -------------------------------------------------------------------------- 
    14591564BackupClientDirectoryRecord::SyncParams::SyncParams(BackupDaemon &rDaemon,  
    1460         ProgressNotifier &rProgressNotifier, BackupClientContext &rContext) 
    1461         : mrProgressNotifier(rProgressNotifier), 
    1462           mSyncPeriodStart(0), 
     1565        BackupClientContext &rContext) 
     1566        : mSyncPeriodStart(0), 
    14631567          mSyncPeriodEnd(0), 
    14641568          mMaxUploadWait(0), 
Note: See TracChangeset for help on using the changeset viewer.