From c0fce877c478ddbf71a1b651c789e5ea00a00144 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:05:30 +0200 Subject: 3.4 --- algorithm.cpp | 117 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 60 deletions(-) (limited to 'algorithm.cpp') diff --git a/algorithm.cpp b/algorithm.cpp index 0940674d..c6690185 100644 --- a/algorithm.cpp +++ b/algorithm.cpp @@ -1,9 +1,16 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** +// #include "algorithm.h" #include #include #include #include "library/resources.h" #include "shared/fileHandling.h" +#include "shared/recycler.h" #include #include "library/filter.h" #include @@ -152,22 +159,14 @@ public: lastWriteTime_(NULL), fileSize_(NULL) { - if (!fileObj.isEmpty()) - { - lastWriteTime_ = &fileObj.getLastWriteTime(); - fileSize_ = &fileObj.getFileSize(); - } + init(fileObj); } DataSetFile(const FileMapping& fileObj, Loki::Int2Type) : lastWriteTime_(NULL), fileSize_(NULL) { - if (!fileObj.isEmpty()) - { - lastWriteTime_ = &fileObj.getLastWriteTime(); - fileSize_ = &fileObj.getFileSize(); - } + init(fileObj); } @@ -207,6 +206,16 @@ public: } private: + template + void init(const FileMapping& fileObj) + { + if (!fileObj.isEmpty()) + { + lastWriteTime_ = &fileObj.getLastWriteTime(); + fileSize_ = &fileObj.getFileSize(); + } + } + const wxLongLong* lastWriteTime_; //optional const wxULongLong* fileSize_; //optional }; @@ -246,7 +255,7 @@ DataSetFile retrieveDataSetFile(const Zstring& objShortName, const DirContainer* { if (dbDirectory) { - const DirContainer::SubFileList& fileList = dbDirectory->getSubFiles(); + const DirContainer::SubFileList& fileList = dbDirectory->getSubFiles(); const DirContainer::SubFileList::const_iterator j = fileList.find(objShortName); if (j != fileList.end()) return DataSetFile(&j->second); @@ -294,6 +303,10 @@ private: void operator()(FileMapping& fileObj) const { const CompareFilesResult cat = fileObj.getCategory(); + + if (cat == FILE_EQUAL) + return; + if (cat == FILE_LEFT_SIDE_ONLY) fileObj.setSyncDir(SYNC_DIR_RIGHT); else if (cat == FILE_RIGHT_SIDE_ONLY) @@ -347,7 +360,7 @@ public: { //use standard settings: SyncConfiguration defaultSync; - defaultSync.setVariant(SyncConfiguration::TWOWAY); + FreeFileSync::setTwoWay(defaultSync); Redetermine(defaultSync).execute(baseDirectory); return; } @@ -387,7 +400,7 @@ private: catch (FileError& error) //e.g. incompatible database version { if (handler_) handler_->reportWarning(error.show() + wxT(" \n\n") + - _("Setting default synchronization directions. Please check whether they are appropriate for you.")); + _("Setting default synchronization directions: Old files will be overwritten by newer files.")); } return std::pair(); //NULL } @@ -514,7 +527,7 @@ private: dirObj.setSyncDir(SYNC_DIR_LEFT); break; case DIR_EQUAL: - assert(false); + ; //assert(false); } SetDirChangedFilter().execute(dirObj); //filter issue for this directory => treat subfiles/-dirs the same @@ -525,15 +538,15 @@ private: const std::pair dataDbLeftStuff = retrieveDataSetDir(dirObj.getObjShortName(), dbDirectoryLeft); const std::pair dataDbRightStuff = retrieveDataSetDir(dirObj.getObjShortName(), dbDirectoryRight); - const DataSetDir dataCurrentLeft( dirObj, Loki::Int2Type()); - const DataSetDir dataCurrentRight(dirObj, Loki::Int2Type()); - - //evaluation - const bool changeOnLeft = dataDbLeftStuff.first != dataCurrentLeft; - const bool changeOnRight = dataDbRightStuff.first != dataCurrentRight; - if (cat != DIR_EQUAL) { + const DataSetDir dataCurrentLeft( dirObj, Loki::Int2Type()); + const DataSetDir dataCurrentRight(dirObj, Loki::Int2Type()); + + //evaluation + const bool changeOnLeft = dataDbLeftStuff.first != dataCurrentLeft; + const bool changeOnRight = dataDbRightStuff.first != dataCurrentRight; + if (dataDbLeftStuff.first == dataDbRightStuff.first) //last sync seems to have been successful { if (changeOnLeft) @@ -882,46 +895,40 @@ void deleteFromGridAndHDOneSide(std::vector& rowsToDeleteOneS { for (std::vector::const_iterator i = rowsToDeleteOneSide.begin(); i != rowsToDeleteOneSide.end(); ++i) { - if (!(*i)->isEmpty()) + while (true) { - while (true) + try { - try + FileSystemObject* const fsObj = *i; //all pointers are required(!) to be bound + if (!fsObj->isEmpty()) { - FileMapping* fileObj = dynamic_cast(*i); - if (fileObj != NULL) - { - FreeFileSync::removeFile(fileObj->getFullName(), useRecycleBin); - fileObj->removeObject(); - statusHandler->deletionSuccessful(); //notify successful file/folder deletion - } + if (useRecycleBin) + FreeFileSync::moveToRecycleBin(fsObj->getFullName()); //throw (FileError) else { - DirMapping* dirObj = dynamic_cast(*i); - if (dirObj != NULL) - { - FreeFileSync::removeDirectory(dirObj->getFullName(), useRecycleBin); - dirObj->removeObject(); //directory: removes recursively! - statusHandler->deletionSuccessful(); //notify successful file/folder deletion - } + if (isDirectoryMapping(*fsObj)) + FreeFileSync::removeDirectory(fsObj->getFullName()); else - assert(!"It's no file, no dir, what is it then?"); + FreeFileSync::removeFile(fsObj->getFullName()); } - break; + fsObj->removeObject(); //if directory: removes recursively! } - catch (const FileError& error) - { - DeleteFilesHandler::Response rv = statusHandler->reportError(error.show()); + statusHandler->deletionSuccessful(); //notify successful file/folder deletion - if (rv == DeleteFilesHandler::IGNORE_ERROR) - break; + break; + } + catch (const FileError& error) + { + DeleteFilesHandler::Response rv = statusHandler->reportError(error.show()); - else if (rv == DeleteFilesHandler::RETRY) - ; //continue in loop - else - assert (false); - } + if (rv == DeleteFilesHandler::IGNORE_ERROR) + break; + + else if (rv == DeleteFilesHandler::RETRY) + ; //continue in loop + else + assert (false); } } } @@ -1146,13 +1153,3 @@ void FreeFileSync::checkForDSTChange(const FileCompareResult& gridData, #endif //FFS_WIN */ - - - - - - - - - - -- cgit