Index: src/libchcore/TSubTaskCopyMove.cpp =================================================================== diff -u -r12a1725bfd04b0f55fd0fda302975fdcd4174943 -r17fff0e0d2496bc8c3d2693b32d5be2c46a9b0fc --- src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 12a1725bfd04b0f55fd0fda302975fdcd4174943) +++ src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 17fff0e0d2496bc8c3d2693b32d5be2c46a9b0fc) @@ -199,30 +199,12 @@ // remove changes in buffer sizes to avoid re-creation later rCfgTracker.RemoveModificationSet(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer); - TBufferSizes bs; - bs.SetOnlyDefault(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetDefaultSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetOneDiskSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetTwoDisksSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetCDSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetLANSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + RecreateBufferIfNeeded(ccp.dbBuffer, true); - ccp.dbBuffer.Create(bs); - - // helpers - DWORD dwLastError = 0; - // log - const TBufferSizes& rbs = ccp.dbBuffer.GetSizes(); - TString strFormat; - strFormat = _T("Processing files/folders (ProcessFiles):\r\n\tOnlyCreate: %create\r\n\tBufferSize: [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize]\r\n\tFiles/folders count: %filecount\r\n\tIgnore Folders: %ignorefolders\r\n\tDest path: %dstpath\r\n\tCurrent index (0-based): %currindex"); + strFormat = _T("Processing files/folders (ProcessFiles):\r\n\tOnlyCreate: %create\r\n\tFiles/folders count: %filecount\r\n\tIgnore Folders: %ignorefolders\r\n\tDest path: %dstpath\r\n\tCurrent index (0-based): %currindex"); strFormat.Replace(_T("%create"), boost::lexical_cast(ccp.bOnlyCreate).c_str()); - strFormat.Replace(_T("%defsize"), boost::lexical_cast(rbs.GetDefaultSize()).c_str()); - strFormat.Replace(_T("%onesize"), boost::lexical_cast(rbs.GetOneDiskSize()).c_str()); - strFormat.Replace(_T("%twosize"), boost::lexical_cast(rbs.GetTwoDisksSize()).c_str()); - strFormat.Replace(_T("%cdsize"), boost::lexical_cast(rbs.GetCDSize()).c_str()); - strFormat.Replace(_T("%lansize"), boost::lexical_cast(rbs.GetLANSize()).c_str()); strFormat.Replace(_T("%filecount"), boost::lexical_cast(stSize).c_str()); strFormat.Replace(_T("%ignorefolders"), boost::lexical_cast(bIgnoreFolders).c_str()); strFormat.Replace(_T("%dstpath"), rTaskDefinition.GetDestinationPath().ToString()); @@ -260,37 +242,10 @@ // if folder - create it if(spFileInfo->IsDirectory()) { - bool bRetry = true; - if(bRetry && !TLocalFilesystem::CreateDirectory(ccp.pathDstFile, false) && (dwLastError = GetLastError()) != ERROR_ALREADY_EXISTS) - { - // log - strFormat = _T("Error %errno while calling CreateDirectory %path (ProcessFiles)"); - strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); - strFormat.Replace(_T("%path"), ccp.pathDstFile.ToString()); - rLog.loge(strFormat); + TSubTaskBase::ESubOperationResult eResult = CreateDirectoryFB(ccp.pathDstFile); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; - FEEDBACK_FILEERROR ferr = { ccp.pathDstFile.ToString(), NULL, eCreateError, dwLastError }; - IFeedbackHandler::EFeedbackResult frResult = (IFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(IFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case IFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; - - case IFeedbackHandler::eResult_Retry: - continue; - - case IFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; - - case IFeedbackHandler::eResult_Skip: - bRetry = false; - break; // just do nothing - default: - BOOST_ASSERT(FALSE); // unknown result - THROW_CORE_EXCEPTION(eErr_UnhandledCase); - } - } - // new stats m_tSubTaskStats.IncreaseProcessedSize(spFileInfo->GetLength64()); @@ -382,7 +337,6 @@ TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); icpf::log_file& rLog = GetContext().GetLog(); - TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); TLocalFilesystemFile fileSrc = TLocalFilesystem::CreateFileObject(); TLocalFilesystemFile fileDst = TLocalFilesystem::CreateFileObject(); @@ -529,38 +483,8 @@ } // recreate buffer if needed - if(rCfgTracker.IsModified() && rCfgTracker.IsModified(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer, true)) - { - TBufferSizes bs; - bs.SetOnlyDefault(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetDefaultSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetOneDiskSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetTwoDisksSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetCDSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - bs.SetLANSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + RecreateBufferIfNeeded(pData->dbBuffer, false); - // log - const TBufferSizes& rbs1 = pData->dbBuffer.GetSizes(); - - strFormat = _T("Changing buffer size from [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize] to [Def:%defsize2, One:%onesize2, Two:%twosize2, CD:%cdsize2, LAN:%lansize2] wile copying %srcfile -> %dstfile (CustomCopyFileFB)"); - - strFormat.Replace(_T("%defsize"), boost::lexical_cast(rbs1.GetDefaultSize()).c_str()); - strFormat.Replace(_T("%onesize"), boost::lexical_cast(rbs1.GetOneDiskSize()).c_str()); - strFormat.Replace(_T("%twosize"), boost::lexical_cast(rbs1.GetTwoDisksSize()).c_str()); - strFormat.Replace(_T("%cdsize"), boost::lexical_cast(rbs1.GetCDSize()).c_str()); - strFormat.Replace(_T("%lansize"), boost::lexical_cast(rbs1.GetLANSize()).c_str()); - strFormat.Replace(_T("%defsize2"), boost::lexical_cast(bs.GetDefaultSize()).c_str()); - strFormat.Replace(_T("%onesize2"), boost::lexical_cast(bs.GetOneDiskSize()).c_str()); - strFormat.Replace(_T("%twosize2"), boost::lexical_cast(bs.GetTwoDisksSize()).c_str()); - strFormat.Replace(_T("%cdsize2"), boost::lexical_cast(bs.GetCDSize()).c_str()); - strFormat.Replace(_T("%lansize2"), boost::lexical_cast(bs.GetLANSize()).c_str()); - strFormat.Replace(_T("%srcfile"), pData->spSrcFile->GetFullFilePath().ToString()); - strFormat.Replace(_T("%dstfile"), pData->pathDstFile.ToString()); - - rLog.logi(strFormat); - pData->dbBuffer.Create(bs); - } - // establish count of data to read if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) iBufferIndex = TBufferSizes::eBuffer_Default; @@ -577,7 +501,7 @@ return eResult; else if(bSkip) { - // old stats + // new stats m_tSubTaskStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - m_tProgressInfo.GetCurrentFileProcessedSize()); pData->bProcessed = false; @@ -697,7 +621,44 @@ return TSubTaskBase::eSubResult_Continue; } +void TSubTaskCopyMove::RecreateBufferIfNeeded(TDataBuffer& rBuffer, bool bInitialCreate) +{ + TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); + TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + icpf::log_file& rLog = GetContext().GetLog(); + if(bInitialCreate || (rCfgTracker.IsModified() && rCfgTracker.IsModified(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer, true))) + { + TBufferSizes bs; + bs.SetOnlyDefault(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + bs.SetDefaultSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + bs.SetOneDiskSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + bs.SetTwoDisksSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + bs.SetCDSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + bs.SetLANSize(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + + // log + const TBufferSizes& rbs1 = rBuffer.GetSizes(); + + TString strFormat; + strFormat = _T("Changing buffer size from [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize] to [Def:%defsize2, One:%onesize2, Two:%twosize2, CD:%cdsize2, LAN:%lansize2]"); + + strFormat.Replace(_T("%defsize"), boost::lexical_cast(rbs1.GetDefaultSize()).c_str()); + strFormat.Replace(_T("%onesize"), boost::lexical_cast(rbs1.GetOneDiskSize()).c_str()); + strFormat.Replace(_T("%twosize"), boost::lexical_cast(rbs1.GetTwoDisksSize()).c_str()); + strFormat.Replace(_T("%cdsize"), boost::lexical_cast(rbs1.GetCDSize()).c_str()); + strFormat.Replace(_T("%lansize"), boost::lexical_cast(rbs1.GetLANSize()).c_str()); + strFormat.Replace(_T("%defsize2"), boost::lexical_cast(bs.GetDefaultSize()).c_str()); + strFormat.Replace(_T("%onesize2"), boost::lexical_cast(bs.GetOneDiskSize()).c_str()); + strFormat.Replace(_T("%twosize2"), boost::lexical_cast(bs.GetTwoDisksSize()).c_str()); + strFormat.Replace(_T("%cdsize2"), boost::lexical_cast(bs.GetCDSize()).c_str()); + strFormat.Replace(_T("%lansize2"), boost::lexical_cast(bs.GetLANSize()).c_str()); + + rLog.logi(strFormat); + rBuffer.Create(bs); + } +} + TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenSourceFileFB(TLocalFilesystemFile& fileSrc, const TSmartPath& spPathToOpen, bool bNoBuffering) { IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); @@ -1145,6 +1106,49 @@ return TSubTaskBase::eSubResult_Continue; } +TSubTaskCopyMove::ESubOperationResult TSubTaskCopyMove::CreateDirectoryFB(const TSmartPath& pathDirectory) +{ + icpf::log_file& rLog = GetContext().GetLog(); + IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + + bool bRetry = true; + DWORD dwLastError = ERROR_SUCCESS; + while(bRetry && !TLocalFilesystem::CreateDirectory(pathDirectory, false) && (dwLastError = GetLastError()) != ERROR_ALREADY_EXISTS) + { + // log + TString strFormat; + strFormat = _T("Error %errno while calling CreateDirectory %path (ProcessFiles)"); + strFormat.Replace(_T("%errno"), boost::lexical_cast(dwLastError).c_str()); + strFormat.Replace(_T("%path"), pathDirectory.ToString()); + rLog.loge(strFormat); + + FEEDBACK_FILEERROR ferr = { pathDirectory.ToString(), NULL, eCreateError, dwLastError }; + IFeedbackHandler::EFeedbackResult frResult = (IFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(IFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case IFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; + + case IFeedbackHandler::eResult_Retry: + bRetry = false; + break; + + case IFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; + + case IFeedbackHandler::eResult_Skip: + bRetry = false; + break; // just do nothing + + default: + BOOST_ASSERT(FALSE); // unknown result + THROW_CORE_EXCEPTION(eErr_UnhandledCase); + } + } + + return TSubTaskBase::eSubResult_Continue; +} + TSubTaskBase::ESubOperationResult TSubTaskCopyMove::CheckForFreeSpaceFB() { icpf::log_file& rLog = GetContext().GetLog(); Index: src/libchcore/TSubTaskCopyMove.h =================================================================== diff -u -r12a1725bfd04b0f55fd0fda302975fdcd4174943 -r17fff0e0d2496bc8c3d2693b32d5be2c46a9b0fc --- src/libchcore/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 12a1725bfd04b0f55fd0fda302975fdcd4174943) +++ src/libchcore/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 17fff0e0d2496bc8c3d2693b32d5be2c46a9b0fc) @@ -83,6 +83,7 @@ private: int GetBufferIndex(const TFileInfoPtr& spFileInfo); + void RecreateBufferIfNeeded(TDataBuffer& rBuffer, bool bInitialCreate); ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData);