Index: src/libchcore/TSubTaskScanDirectory.cpp =================================================================== diff -u -N -r9ebcc7abf1e0e70f0db2d08b2691351a26ef259b -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 9ebcc7abf1e0e70f0db2d08b2691351a26ef259b) +++ src/libchcore/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -39,243 +39,241 @@ #include "TFeedbackHandlerWrapper.h" #include "TBufferSizes.h" -BEGIN_CHCORE_NAMESPACE - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// class TSubTaskScanDirectories -TSubTaskScanDirectories::TSubTaskScanDirectories(TSubTaskContext& rContext) : - TSubTaskBase(rContext), - m_tSubTaskStats(eSubOperation_Scanning) +namespace chcore { -} + /////////////////////////////////////////////////////////////////////////////////////////////////// + // class TSubTaskScanDirectories + TSubTaskScanDirectories::TSubTaskScanDirectories(TSubTaskContext& rContext) : + TSubTaskBase(rContext), + m_tSubTaskStats(eSubOperation_Scanning) + { + } -TSubTaskScanDirectories::~TSubTaskScanDirectories() -{ -} + TSubTaskScanDirectories::~TSubTaskScanDirectories() + { + } -void TSubTaskScanDirectories::Reset() -{ - m_tSubTaskStats.Clear(); -} + void TSubTaskScanDirectories::Reset() + { + m_tSubTaskStats.Clear(); + } -TSubTaskScanDirectories::ESubOperationResult TSubTaskScanDirectories::Exec(const IFeedbackHandlerPtr& spFeedback) -{ - TScopedRunningTimeTracker guard(m_tSubTaskStats); - TFeedbackHandlerWrapperPtr spFeedbackHandler(boost::make_shared(spFeedback, guard)); + TSubTaskScanDirectories::ESubOperationResult TSubTaskScanDirectories::Exec(const IFeedbackHandlerPtr& spFeedback) + { + TScopedRunningTimeTracker guard(m_tSubTaskStats); + TFeedbackHandlerWrapperPtr spFeedbackHandler(boost::make_shared(spFeedback, guard)); - // log - icpf::log_file& rLog = GetContext().GetLog(); - TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); - const TConfig& rConfig = GetContext().GetConfig(); - const TFileFiltersArray& rafFilters = GetContext().GetFilters(); - const IFilesystemPtr& spFilesystem = GetContext().GetLocalFilesystem(); + // log + icpf::log_file& rLog = GetContext().GetLog(); + TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); + const TConfig& rConfig = GetContext().GetConfig(); + const TFileFiltersArray& rafFilters = GetContext().GetFilters(); + const IFilesystemPtr& spFilesystem = GetContext().GetLocalFilesystem(); - rLog.logi(_T("Searching for files...")); + rLog.logi(_T("Searching for files...")); - // reset progress - rFilesCache.SetComplete(false); + // reset progress + rFilesCache.SetComplete(false); - // new stats - m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); - m_tSubTaskStats.SetTotalCount(spBasePaths->GetCount()); - m_tSubTaskStats.SetProcessedCount(0); - m_tSubTaskStats.SetTotalSize(0); - m_tSubTaskStats.SetProcessedSize(0); - m_tSubTaskStats.SetCurrentPath(TString()); + // new stats + m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); + m_tSubTaskStats.SetTotalCount(spBasePaths->GetCount()); + m_tSubTaskStats.SetProcessedCount(0); + m_tSubTaskStats.SetTotalSize(0); + m_tSubTaskStats.SetProcessedSize(0); + m_tSubTaskStats.SetCurrentPath(TString()); - // delete the content of rFilesCache - rFilesCache.Clear(); + // delete the content of rFilesCache + rFilesCache.Clear(); - bool bIgnoreDirs = GetTaskPropValue(rConfig); - bool bForceDirectories = GetTaskPropValue(rConfig); + bool bIgnoreDirs = GetTaskPropValue(rConfig); + bool bForceDirectories = GetTaskPropValue(rConfig); - // add everything - TString strFormat; - bool bRetry = true; - bool bSkipInputPath = false; + // add everything + TString strFormat; + bool bRetry = true; + bool bSkipInputPath = false; - file_count_t fcSize = spBasePaths->GetCount(); - // NOTE: in theory, we should resume the scanning, but in practice we are always restarting scanning if interrupted. - file_count_t fcIndex = 0; // m_tSubTaskStats.GetCurrentIndex() - for(; fcIndex < fcSize; fcIndex++) - { - TBasePathDataPtr spBasePath = spBasePaths->GetAt(fcIndex); - TSmartPath pathCurrent = spBasePath->GetSrcPath(); + file_count_t fcSize = spBasePaths->GetCount(); + // NOTE: in theory, we should resume the scanning, but in practice we are always restarting scanning if interrupted. + file_count_t fcIndex = 0; // m_tSubTaskStats.GetCurrentIndex() + for (; fcIndex < fcSize; fcIndex++) + { + TBasePathDataPtr spBasePath = spBasePaths->GetAt(fcIndex); + TSmartPath pathCurrent = spBasePath->GetSrcPath(); - m_tSubTaskStats.SetCurrentIndex(fcIndex); + m_tSubTaskStats.SetCurrentIndex(fcIndex); - // new stats - m_tSubTaskStats.SetProcessedCount(fcIndex); - m_tSubTaskStats.SetCurrentPath(pathCurrent.ToString()); + // new stats + m_tSubTaskStats.SetProcessedCount(fcIndex); + m_tSubTaskStats.SetCurrentPath(pathCurrent.ToString()); - bSkipInputPath = false; - TFileInfoPtr spFileInfo(boost::make_shared()); + bSkipInputPath = false; + TFileInfoPtr spFileInfo(boost::make_shared()); - // check if we want to process this path at all (might be already fast moved) - if(spBasePath->GetSkipFurtherProcessing()) - continue; + // check if we want to process this path at all (might be already fast moved) + if (spBasePath->GetSkipFurtherProcessing()) + continue; - // try to get some info about the input path; let user know if the path does not exist. - do - { - bRetry = false; - - // read attributes of src file/folder - bool bExists = spFilesystem->GetFileInfo(pathCurrent, spFileInfo, spBasePath); - if(!bExists) + // try to get some info about the input path; let user know if the path does not exist. + do { - EFeedbackResult frResult = spFeedbackHandler->FileError(pathCurrent.ToWString(), TString(), EFileError::eFastMoveError, ERROR_FILE_NOT_FOUND); - switch(frResult) + bRetry = false; + + // read attributes of src file/folder + bool bExists = spFilesystem->GetFileInfo(pathCurrent, spFileInfo, spBasePath); + if (!bExists) { - case EFeedbackResult::eResult_Cancel: - rFilesCache.Clear(); - return eSubResult_CancelRequest; + EFeedbackResult frResult = spFeedbackHandler->FileError(pathCurrent.ToWString(), TString(), EFileError::eFastMoveError, ERROR_FILE_NOT_FOUND); + switch (frResult) + { + case EFeedbackResult::eResult_Cancel: + rFilesCache.Clear(); + return eSubResult_CancelRequest; - case EFeedbackResult::eResult_Retry: - bRetry = true; - break; + case EFeedbackResult::eResult_Retry: + bRetry = true; + break; - case EFeedbackResult::eResult_Pause: - rFilesCache.Clear(); - return eSubResult_PauseRequest; + case EFeedbackResult::eResult_Pause: + rFilesCache.Clear(); + return eSubResult_PauseRequest; - case EFeedbackResult::eResult_Skip: - bSkipInputPath = true; - break; // just do nothing + case EFeedbackResult::eResult_Skip: + bSkipInputPath = true; + break; // just do nothing - default: - BOOST_ASSERT(FALSE); // unknown result - THROW_CORE_EXCEPTION(eErr_UnhandledCase); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW_CORE_EXCEPTION(eErr_UnhandledCase); + } } - } - } - while(bRetry); + } while (bRetry); - // if we have chosen to skip the input path then there's nothing to do - if(bSkipInputPath) - continue; + // if we have chosen to skip the input path then there's nothing to do + if (bSkipInputPath) + continue; - // log - strFormat = _T("Adding file/folder (clipboard) : %path ..."); - strFormat.Replace(_T("%path"), pathCurrent.ToString()); - rLog.logi(strFormat.c_str()); + // log + strFormat = _T("Adding file/folder (clipboard) : %path ..."); + strFormat.Replace(_T("%path"), pathCurrent.ToString()); + rLog.logi(strFormat.c_str()); - // add if needed - if(spFileInfo->IsDirectory()) - { - // add if folder's aren't ignored - if(!bIgnoreDirs && !bForceDirectories) + // add if needed + if (spFileInfo->IsDirectory()) { - // add directory info; it is not to be filtered with afFilters - rFilesCache.AddFileInfo(spFileInfo); + // add if folder's aren't ignored + if (!bIgnoreDirs && !bForceDirectories) + { + // add directory info; it is not to be filtered with afFilters + rFilesCache.AddFileInfo(spFileInfo); + // log + strFormat = _T("Added folder %path"); + strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); + rLog.logi(strFormat.c_str()); + } + + // don't add folder contents when moving inside one disk boundary // log - strFormat = _T("Added folder %path"); - strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); + strFormat = _T("Recursing folder %path"); + strFormat.Replace(_t("%path"), spFileInfo->GetFullFilePath().ToString()); rLog.logi(strFormat.c_str()); - } - // don't add folder contents when moving inside one disk boundary - // log - strFormat = _T("Recursing folder %path"); - strFormat.Replace(_t("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.logi(strFormat.c_str()); + ScanDirectory(spFileInfo->GetFullFilePath(), spBasePath, true, !bIgnoreDirs || bForceDirectories, rafFilters); - ScanDirectory(spFileInfo->GetFullFilePath(), spBasePath, true, !bIgnoreDirs || bForceDirectories, rafFilters); - - // check for kill need - if(rThreadController.KillRequested()) + // check for kill need + if (rThreadController.KillRequested()) + { + // log + rLog.logi(_T("Kill request while adding data to files array (RecurseDirectories)")); + rFilesCache.Clear(); + return eSubResult_KillRequest; + } + } + else { + // add file info if passes filters + if (rafFilters.Match(spFileInfo)) + rFilesCache.AddFileInfo(spFileInfo); + // log - rLog.logi(_T("Kill request while adding data to files array (RecurseDirectories)")); - rFilesCache.Clear(); - return eSubResult_KillRequest; + strFormat = _T("Added file %path"); + strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); + rLog.logi(strFormat.c_str()); } } - else - { - // add file info if passes filters - if(rafFilters.Match(spFileInfo)) - rFilesCache.AddFileInfo(spFileInfo); - // log - strFormat = _T("Added file %path"); - strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.logi(strFormat.c_str()); - } - } + // update stats + m_tSubTaskStats.SetCurrentIndex(fcIndex); + m_tSubTaskStats.SetProcessedCount(fcIndex); + m_tSubTaskStats.SetCurrentPath(TString()); - // update stats - m_tSubTaskStats.SetCurrentIndex(fcIndex); - m_tSubTaskStats.SetProcessedCount(fcIndex); - m_tSubTaskStats.SetCurrentPath(TString()); + rFilesCache.SetComplete(true); - rFilesCache.SetComplete(true); + // log + rLog.logi(_T("Searching for files finished")); - // log - rLog.logi(_T("Searching for files finished")); + return eSubResult_Continue; + } - return eSubResult_Continue; -} + void TSubTaskScanDirectories::GetStatsSnapshot(TSubTaskStatsSnapshotPtr& spStats) const + { + m_tSubTaskStats.GetSnapshot(spStats); + } -void TSubTaskScanDirectories::GetStatsSnapshot(TSubTaskStatsSnapshotPtr& spStats) const -{ - m_tSubTaskStats.GetSnapshot(spStats); -} - -int TSubTaskScanDirectories::ScanDirectory(TSmartPath pathDirName, const TBasePathDataPtr& spBasePathData, - bool bRecurse, bool bIncludeDirs, const TFileFiltersArray& afFilters) -{ - TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); - const IFilesystemPtr& spFilesystem = GetContext().GetLocalFilesystem(); - - IFilesystemFindPtr spFinder = spFilesystem->CreateFinderObject(pathDirName, PathFromString(_T("*"))); - TFileInfoPtr spFileInfo(boost::make_shared()); - - while(spFinder->FindNext(spFileInfo)) + int TSubTaskScanDirectories::ScanDirectory(TSmartPath pathDirName, const TBasePathDataPtr& spBasePathData, + bool bRecurse, bool bIncludeDirs, const TFileFiltersArray& afFilters) { - if(rThreadController.KillRequested()) - break; + TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + TBasePathDataContainerPtr spBasePaths = GetContext().GetBasePaths(); + const IFilesystemPtr& spFilesystem = GetContext().GetLocalFilesystem(); - if(!spFileInfo->IsDirectory()) + IFilesystemFindPtr spFinder = spFilesystem->CreateFinderObject(pathDirName, PathFromString(_T("*"))); + TFileInfoPtr spFileInfo(boost::make_shared()); + + while (spFinder->FindNext(spFileInfo)) { - if(afFilters.Match(spFileInfo)) + if (rThreadController.KillRequested()) + break; + + if (!spFileInfo->IsDirectory()) { - spFileInfo->SetParentObject(spBasePathData); - rFilesCache.AddFileInfo(spFileInfo); - spFileInfo = boost::make_shared(); + if (afFilters.Match(spFileInfo)) + { + spFileInfo->SetParentObject(spBasePathData); + rFilesCache.AddFileInfo(spFileInfo); + spFileInfo = boost::make_shared(); + } } - } - else - { - TSmartPath pathCurrent = spFileInfo->GetFullFilePath(); - if(bIncludeDirs) + else { - spFileInfo->SetParentObject(spBasePathData); - rFilesCache.AddFileInfo(spFileInfo); - spFileInfo = boost::make_shared(); - } + TSmartPath pathCurrent = spFileInfo->GetFullFilePath(); + if (bIncludeDirs) + { + spFileInfo->SetParentObject(spBasePathData); + rFilesCache.AddFileInfo(spFileInfo); + spFileInfo = boost::make_shared(); + } - if(bRecurse) - ScanDirectory(pathCurrent, spBasePathData, bRecurse, bIncludeDirs, afFilters); + if (bRecurse) + ScanDirectory(pathCurrent, spBasePathData, bRecurse, bIncludeDirs, afFilters); + } } + + return 0; } - return 0; -} + void TSubTaskScanDirectories::Store(const ISerializerPtr& spSerializer) const + { + spSerializer; + } -void TSubTaskScanDirectories::Store(const ISerializerPtr& spSerializer) const -{ - spSerializer; + void TSubTaskScanDirectories::Load(const ISerializerPtr& spSerializer) + { + spSerializer; + } } - -void TSubTaskScanDirectories::Load(const ISerializerPtr& spSerializer) -{ - spSerializer; -} - -END_CHCORE_NAMESPACE