Index: src/libchcore/TSubTaskDelete.cpp =================================================================== diff -u -N -r9ebcc7abf1e0e70f0db2d08b2691351a26ef259b -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision 9ebcc7abf1e0e70f0db2d08b2691351a26ef259b) +++ src/libchcore/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -39,174 +39,173 @@ #include #include "TBufferSizes.h" -BEGIN_CHCORE_NAMESPACE - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// class TSubTaskDelete - -TSubTaskDelete::TSubTaskDelete(TSubTaskContext& rContext) : - TSubTaskBase(rContext), - m_tSubTaskStats(eSubOperation_Deleting) +namespace chcore { -} + /////////////////////////////////////////////////////////////////////////////////////////////////// + // class TSubTaskDelete -void TSubTaskDelete::Reset() -{ - m_tSubTaskStats.Clear(); -} + TSubTaskDelete::TSubTaskDelete(TSubTaskContext& rContext) : + TSubTaskBase(rContext), + m_tSubTaskStats(eSubOperation_Deleting) + { + } -TSubTaskBase::ESubOperationResult TSubTaskDelete::Exec(const IFeedbackHandlerPtr& spFeedback) -{ - TScopedRunningTimeTracker guard(m_tSubTaskStats); - TFeedbackHandlerWrapperPtr spFeedbackHandler(boost::make_shared(spFeedback, guard)); + void TSubTaskDelete::Reset() + { + m_tSubTaskStats.Clear(); + } - // log - icpf::log_file& rLog = GetContext().GetLog(); - TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - const TConfig& rConfig = GetContext().GetConfig(); - IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); + TSubTaskBase::ESubOperationResult TSubTaskDelete::Exec(const IFeedbackHandlerPtr& spFeedback) + { + TScopedRunningTimeTracker guard(m_tSubTaskStats); + TFeedbackHandlerWrapperPtr spFeedbackHandler(boost::make_shared(spFeedback, guard)); - // log - rLog.logi(_T("Deleting files (DeleteFiles)...")); + // log + icpf::log_file& rLog = GetContext().GetLog(); + TFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + const TConfig& rConfig = GetContext().GetConfig(); + IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - // new stats - m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); - m_tSubTaskStats.SetTotalCount(rFilesCache.GetSize()); - m_tSubTaskStats.SetProcessedCount(0); - m_tSubTaskStats.SetTotalSize(0); - m_tSubTaskStats.SetProcessedSize(0); - m_tSubTaskStats.SetCurrentPath(TString()); + // log + rLog.logi(_T("Deleting files (DeleteFiles)...")); - // current processed path - BOOL bSuccess; - TFileInfoPtr spFileInfo; - TString strFormat; + // new stats + m_tSubTaskStats.SetCurrentBufferIndex(TBufferSizes::eBuffer_Default); + m_tSubTaskStats.SetTotalCount(rFilesCache.GetSize()); + m_tSubTaskStats.SetProcessedCount(0); + m_tSubTaskStats.SetTotalSize(0); + m_tSubTaskStats.SetProcessedSize(0); + m_tSubTaskStats.SetCurrentPath(TString()); - // index points to 0 or next item to process - file_count_t fcIndex = m_tSubTaskStats.GetCurrentIndex(); - while(fcIndex < rFilesCache.GetSize()) - { - spFileInfo = rFilesCache.GetAt(rFilesCache.GetSize() - fcIndex - 1); + // current processed path + BOOL bSuccess; + TFileInfoPtr spFileInfo; + TString strFormat; - m_tSubTaskStats.SetCurrentIndex(fcIndex); + // index points to 0 or next item to process + file_count_t fcIndex = m_tSubTaskStats.GetCurrentIndex(); + while (fcIndex < rFilesCache.GetSize()) + { + spFileInfo = rFilesCache.GetAt(rFilesCache.GetSize() - fcIndex - 1); - // new stats - m_tSubTaskStats.SetProcessedCount(fcIndex); - m_tSubTaskStats.SetCurrentPath(spFileInfo->GetFullFilePath().ToString()); + m_tSubTaskStats.SetCurrentIndex(fcIndex); - // check for kill flag - if(rThreadController.KillRequested()) - { - // log - rLog.logi(_T("Kill request while deleting files (Delete Files)")); - return TSubTaskBase::eSubResult_KillRequest; - } + // new stats + m_tSubTaskStats.SetProcessedCount(fcIndex); + m_tSubTaskStats.SetCurrentPath(spFileInfo->GetFullFilePath().ToString()); - // current processed element - if(!spFileInfo->IsProcessed()) - { - ++fcIndex; - continue; - } + // check for kill flag + if (rThreadController.KillRequested()) + { + // log + rLog.logi(_T("Kill request while deleting files (Delete Files)")); + return TSubTaskBase::eSubResult_KillRequest; + } - // delete data - if(spFileInfo->IsDirectory()) - { - if(!GetTaskPropValue(rConfig)) - spFilesystem->SetAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); - bSuccess = spFilesystem->RemoveDirectory(spFileInfo->GetFullFilePath()); - } - else - { - // set files attributes to normal - it'd slow processing a bit, but it's better. - if(!GetTaskPropValue(rConfig)) - spFilesystem->SetAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); - bSuccess = spFilesystem->DeleteFile(spFileInfo->GetFullFilePath()); - } + // current processed element + if (!spFileInfo->IsProcessed()) + { + ++fcIndex; + continue; + } - // operation failed - DWORD dwLastError = GetLastError(); - if(!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) - { - // log - strFormat = _T("Error #%errno while deleting file/folder %path"); - strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); - strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); - rLog.loge(strFormat.c_str()); + // delete data + if (spFileInfo->IsDirectory()) + { + if (!GetTaskPropValue(rConfig)) + spFilesystem->SetAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + bSuccess = spFilesystem->RemoveDirectory(spFileInfo->GetFullFilePath()); + } + else + { + // set files attributes to normal - it'd slow processing a bit, but it's better. + if (!GetTaskPropValue(rConfig)) + spFilesystem->SetAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); + bSuccess = spFilesystem->DeleteFile(spFileInfo->GetFullFilePath()); + } - EFeedbackResult frResult = spFeedbackHandler->FileError(spFileInfo->GetFullFilePath().ToWString(), TString(), EFileError::eDeleteError, dwLastError); - switch(frResult) + // operation failed + DWORD dwLastError = GetLastError(); + if (!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) { - case EFeedbackResult::eResult_Cancel: - rLog.logi(_T("Cancel request while deleting file.")); - return TSubTaskBase::eSubResult_CancelRequest; + // log + strFormat = _T("Error #%errno while deleting file/folder %path"); + strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); + strFormat.Replace(_T("%path"), spFileInfo->GetFullFilePath().ToString()); + rLog.loge(strFormat.c_str()); - case EFeedbackResult::eResult_Retry: - continue; // no fcIndex bump, since we are trying again + EFeedbackResult frResult = spFeedbackHandler->FileError(spFileInfo->GetFullFilePath().ToWString(), TString(), EFileError::eDeleteError, dwLastError); + switch (frResult) + { + case EFeedbackResult::eResult_Cancel: + rLog.logi(_T("Cancel request while deleting file.")); + return TSubTaskBase::eSubResult_CancelRequest; - case EFeedbackResult::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case EFeedbackResult::eResult_Retry: + continue; // no fcIndex bump, since we are trying again - case EFeedbackResult::eResult_Skip: - break; // just do nothing + case EFeedbackResult::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW_CORE_EXCEPTION(eErr_UnhandledCase); + case EFeedbackResult::eResult_Skip: + break; // just do nothing + + default: + BOOST_ASSERT(FALSE); // unknown result + THROW_CORE_EXCEPTION(eErr_UnhandledCase); + } } - } - ++fcIndex; - }//while + ++fcIndex; + }//while - m_tSubTaskStats.SetCurrentIndex(fcIndex); - m_tSubTaskStats.SetProcessedCount(fcIndex); - m_tSubTaskStats.SetCurrentPath(TString()); + m_tSubTaskStats.SetCurrentIndex(fcIndex); + m_tSubTaskStats.SetProcessedCount(fcIndex); + m_tSubTaskStats.SetCurrentPath(TString()); - // log - rLog.logi(_T("Deleting files finished")); + // log + rLog.logi(_T("Deleting files finished")); - return TSubTaskBase::eSubResult_Continue; -} + return TSubTaskBase::eSubResult_Continue; + } -void TSubTaskDelete::GetStatsSnapshot(TSubTaskStatsSnapshotPtr& spStats) const -{ - m_tSubTaskStats.GetSnapshot(spStats); - // if this subtask is not started yet, try to get the most fresh information for processing - if(!spStats->IsRunning() && spStats->GetTotalCount() == 0 && spStats->GetTotalSize() == 0) + void TSubTaskDelete::GetStatsSnapshot(TSubTaskStatsSnapshotPtr& spStats) const { - spStats->SetTotalCount(GetContext().GetFilesCache().GetSize()); - spStats->SetTotalSize(0); + m_tSubTaskStats.GetSnapshot(spStats); + // if this subtask is not started yet, try to get the most fresh information for processing + if (!spStats->IsRunning() && spStats->GetTotalCount() == 0 && spStats->GetTotalSize() == 0) + { + spStats->SetTotalCount(GetContext().GetFilesCache().GetSize()); + spStats->SetTotalSize(0); + } } -} -void TSubTaskDelete::Store(const ISerializerPtr& spSerializer) const -{ - ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("subtask_delete")); - InitColumns(spContainer); + void TSubTaskDelete::Store(const ISerializerPtr& spSerializer) const + { + ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("subtask_delete")); + InitColumns(spContainer); - ISerializerRowData& rRow = spContainer->GetRow(0, m_tSubTaskStats.WasAdded()); + ISerializerRowData& rRow = spContainer->GetRow(0, m_tSubTaskStats.WasAdded()); - m_tSubTaskStats.Store(rRow); -} + m_tSubTaskStats.Store(rRow); + } -void TSubTaskDelete::Load(const ISerializerPtr& spSerializer) -{ - ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("subtask_delete")); + void TSubTaskDelete::Load(const ISerializerPtr& spSerializer) + { + ISerializerContainerPtr spContainer = spSerializer->GetContainer(_T("subtask_delete")); - InitColumns(spContainer); + InitColumns(spContainer); - ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); - if(spRowReader->Next()) - m_tSubTaskStats.Load(spRowReader); -} + ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); + if (spRowReader->Next()) + m_tSubTaskStats.Load(spRowReader); + } -void TSubTaskDelete::InitColumns(const ISerializerContainerPtr& spContainer) const -{ - IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); - if(rColumns.IsEmpty()) - TSubTaskStatsInfo::InitColumns(rColumns); + void TSubTaskDelete::InitColumns(const ISerializerContainerPtr& spContainer) const + { + IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); + if (rColumns.IsEmpty()) + TSubTaskStatsInfo::InitColumns(rColumns); + } } - -END_CHCORE_NAMESPACE