Index: src/libchcore/TBasePathData.cpp =================================================================== diff -u -N -rf866db90e4b058a4f2e13cc6cf076d1e0bf2d956 -ref2ea2589f6eeed54f8001fee72936198172ceed --- src/libchcore/TBasePathData.cpp (.../TBasePathData.cpp) (revision f866db90e4b058a4f2e13cc6cf076d1e0bf2d956) +++ src/libchcore/TBasePathData.cpp (.../TBasePathData.cpp) (revision ef2ea2589f6eeed54f8001fee72936198172ceed) @@ -59,12 +59,14 @@ m_bSkipFurtherProcessing(m_setModifications, false), m_pathDst(m_setModifications) { + m_pathSrc.Modify().StripSeparatorAtEnd(); m_setModifications[eMod_Added] = true; } void TBasePathData::SetDestinationPath(const TSmartPath& tPath) { m_pathDst = tPath; + m_pathDst.Modify().StripSeparatorAtEnd(); } TSmartPath TBasePathData::GetDestinationPath() const @@ -121,6 +123,10 @@ spRowReader->GetValue(_T("src_path"), m_pathSrc.Modify()); spRowReader->GetValue(_T("skip_processing"), m_bSkipFurtherProcessing.Modify()); spRowReader->GetValue(_T("dst_path"), m_pathDst.Modify()); + + m_pathSrc.Modify().StripSeparatorAtEnd(); + m_pathDst.Modify().StripSeparatorAtEnd(); + m_setModifications.reset(); } Index: src/libchcore/TDestinationPathProvider.cpp =================================================================== diff -u -N -r7ba9f25ab2c2a42bac9f5455ecb98aaf6e29f02d -ref2ea2589f6eeed54f8001fee72936198172ceed --- src/libchcore/TDestinationPathProvider.cpp (.../TDestinationPathProvider.cpp) (revision 7ba9f25ab2c2a42bac9f5455ecb98aaf6e29f02d) +++ src/libchcore/TDestinationPathProvider.cpp (.../TDestinationPathProvider.cpp) (revision ef2ea2589f6eeed54f8001fee72936198172ceed) @@ -24,52 +24,76 @@ throw TCoreException(eErr_InvalidArgument, L"spFilesystem", LOCATION); } - TSmartPath TDestinationPathProvider::CalculateDestinationPath(const TFileInfoPtr& spFileInfo) { if(!spFileInfo) throw TCoreException(eErr_InvalidArgument, L"spFileInfo", LOCATION); - if(m_bForceDirectories) - { - // force create directories - TSmartPath pathCombined = m_pathDestinationBase + spFileInfo->GetFullFilePath().GetFileDir(); + if (m_bForceDirectories) + return CalculateForceDirectories(spFileInfo); - // force create directory - m_spFilesystem->CreateDirectory(pathCombined, true); + if (m_bIgnoreFolders) + return CalculateIgnoreDirectories(spFileInfo); - return pathCombined + spFileInfo->GetFullFilePath().GetFileName(); - } - else - { - TBasePathDataPtr spPathData = spFileInfo->GetBasePathData(); + TBasePathDataPtr spPathData = spFileInfo->GetBasePathData(); + if(!spPathData) + return m_pathDestinationBase + spFileInfo->GetFilePath(); - if(!m_bIgnoreFolders && spPathData) + // generate new dest name + if(!spPathData->IsDestinationPathSet()) + { + // generate something - if dest folder == src folder - search for copy + if(m_pathDestinationBase == spFileInfo->GetFullFilePath().GetFileRoot()) { - // generate new dest name - if(!spPathData->IsDestinationPathSet()) - { - // generate something - if dest folder == src folder - search for copy - if(m_pathDestinationBase == spFileInfo->GetFullFilePath().GetFileRoot()) - { - TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath()); - spPathData->SetDestinationPath(pathSubst); - } - else - { - TSmartPath pathFilename = spFileInfo->GetFullFilePath().GetFileName(); - pathFilename.StripPath(L":"); - spPathData->SetDestinationPath(pathFilename); - } - } - - return m_pathDestinationBase + spPathData->GetDestinationPath() + spFileInfo->GetFilePath(); + TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath()); + spPathData->SetDestinationPath(pathSubst); } else - return m_pathDestinationBase + spFileInfo->GetFilePath(); + { + TSmartPath pathFilename = spPathData->GetSrcPath(); + pathFilename.StripSeparatorAtEnd(); + pathFilename.StripPath(L":"); + + spPathData->SetDestinationPath(pathFilename.GetFileName()); + } } + + TSmartPath pathResult = m_pathDestinationBase + spPathData->GetDestinationPath() + spFileInfo->GetFilePath(); + pathResult.StripSeparatorAtEnd(); + + return pathResult; } + TSmartPath TDestinationPathProvider::CalculateForceDirectories(const TFileInfoPtr& spFileInfo) + { + // force create directories + TSmartPath tFileRoot = spFileInfo->GetFullFilePath().GetFileRoot(); + tFileRoot.StripPath(L":"); + + TSmartPath pathCombined = m_pathDestinationBase + tFileRoot; + + // force create directory + m_spFilesystem->CreateDirectory(pathCombined, true); + + TSmartPath pathFile = spFileInfo->GetFullFilePath().GetFileName(); + pathFile.StripPath(L":"); + TSmartPath pathResult = pathCombined + pathFile; + pathResult.StripSeparatorAtEnd(); + + return pathResult; + } + + TSmartPath TDestinationPathProvider::CalculateIgnoreDirectories(const TFileInfoPtr& spFileInfo) + { + TSmartPath pathFilename = spFileInfo->GetFullFilePath(); + pathFilename.StripPath(L":"); + pathFilename.StripSeparatorAtEnd(); + + TSmartPath pathResult = m_pathDestinationBase + pathFilename.GetFileName(); + + return pathResult; + } + // finds another name for a copy of src file(folder) in dest location TSmartPath TDestinationPathProvider::FindFreeSubstituteName(TSmartPath pathSrcPath) const { Index: src/libchcore/TDestinationPathProvider.h =================================================================== diff -u -N -r7ba9f25ab2c2a42bac9f5455ecb98aaf6e29f02d -ref2ea2589f6eeed54f8001fee72936198172ceed --- src/libchcore/TDestinationPathProvider.h (.../TDestinationPathProvider.h) (revision 7ba9f25ab2c2a42bac9f5455ecb98aaf6e29f02d) +++ src/libchcore/TDestinationPathProvider.h (.../TDestinationPathProvider.h) (revision ef2ea2589f6eeed54f8001fee72936198172ceed) @@ -34,6 +34,8 @@ TSmartPath CalculateDestinationPath(const TFileInfoPtr& spFileInfo); private: + TSmartPath CalculateForceDirectories(const TFileInfoPtr& spFileInfo); + TSmartPath CalculateIgnoreDirectories(const TFileInfoPtr& spFileInfo); TSmartPath FindFreeSubstituteName(TSmartPath pathSrcPath) const; private: Index: src/libchcore/Tests/TestsTDestinationPathProvider.cpp =================================================================== diff -u -N -rc0120993b38b7f0759e0887fd0e5a03dcced68de -ref2ea2589f6eeed54f8001fee72936198172ceed --- src/libchcore/Tests/TestsTDestinationPathProvider.cpp (.../TestsTDestinationPathProvider.cpp) (revision c0120993b38b7f0759e0887fd0e5a03dcced68de) +++ src/libchcore/Tests/TestsTDestinationPathProvider.cpp (.../TestsTDestinationPathProvider.cpp) (revision ef2ea2589f6eeed54f8001fee72936198172ceed) @@ -60,8 +60,59 @@ } }; +// base src path, full src path, is file, destination path, ignore folders, force directories, expected resulting path INSTANTIATE_TEST_CASE_P(BasicTransformTests, TransformTest, ::testing::Values( - std::make_tuple(TString(L"c:"), TString(L"c:"), true, TString(L"x:\\"), false, false, TString(L"x:\\c")) + ///////////////////////////////////////// + // full drive copy, std options, root + std::make_tuple(TString(L"c:"), TString(L"c:"), false, TString(L"x:\\"), false, false, TString(L"x:\\c")), // 0 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\"), false, TString(L"x:\\"), false, false, TString(L"x:\\c")), // 1 + // full drive copy, ignore folders, root + std::make_tuple(TString(L"c:"), TString(L"c:"), false, TString(L"x:\\"), true, false, TString(L"x:\\c")), // 2 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\"), false, TString(L"x:\\"), true, false, TString(L"x:\\c")), // 3 + // full drive copy, force directories, root + std::make_tuple(TString(L"c:"), TString(L"c:"), false, TString(L"x:\\"), false, true, TString(L"x:\\c")), // 4 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\"), false, TString(L"x:\\"), false, true, TString(L"x:\\c")), // 5 + + ///////////////////////////////////////// + // full drive copy, std options, non-root + std::make_tuple(TString(L"c:"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), false, false, TString(L"x:\\c\\folder\\file.txt")), // 6 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), false, false, TString(L"x:\\c\\folder\\file.txt")), // 7 + // full drive copy, ignore folders, non-root + std::make_tuple(TString(L"c:"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), true, false, TString(L"x:\\file.txt")), // 8 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), true, false, TString(L"x:\\file.txt")), // 9 + // full drive copy, force directories, non-root + std::make_tuple(TString(L"c:"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder\\file.txt")), // 10 + std::make_tuple(TString(L"c:\\"), TString(L"c:\\folder\\file.txt"), true, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder\\file.txt")), // 11 + + ///////////////////////////////////////// + // folder copy, std options, folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder"), false, TString(L"x:\\"), false, false, TString(L"x:\\folder")), // 12 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\"), false, TString(L"x:\\"), false, false, TString(L"x:\\folder")), // 13 + // folder copy, ignore folders, folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder"), false, TString(L"x:\\"), true, false, TString(L"x:\\folder")), // 14 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\"), false, TString(L"x:\\"), true, false, TString(L"x:\\folder")), // 15 + // folder copy, force directories, folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder"), false, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder")), // 16 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\"), false, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder")), // 17 + + ///////////////////////////////////////// + // folder copy, std options, non folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), false, false, TString(L"x:\\folder\\folder2\\file.txt")), // 18 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), false, false, TString(L"x:\\folder\\folder2\\file.txt")), // 19 + // folder copy, ignore folders, non folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), true, false, TString(L"x:\\file.txt")), // 20 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), true, false, TString(L"x:\\file.txt")), // 21 + // folder copy, force directories, non folder root + std::make_tuple(TString(L"c:\\folder"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder\\folder2\\file.txt")), // 22 + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder\\folder2\\file.txt"), true, TString(L"x:\\"), false, true, TString(L"x:\\c\\folder\\folder2\\file.txt")), // 23 + + ///////////////////////////////////////// + // special cases + // base path slightly differs from normal path (by a separator which should be ignored) + std::make_tuple(TString(L"c:\\folder\\"), TString(L"c:\\folder"), false, TString(L"x:\\"), false, false, TString(L"x:\\folder")), // 24 + + // case insensitivity + std::make_tuple(TString(L"c:\\Folder"), TString(L"c:\\folder"), false, TString(L"x:\\"), false, false, TString(L"x:\\Folder")) // 25 )); TEST_P(TransformTest, PathTest) @@ -79,9 +130,9 @@ bool bForceDirectories = std::get<5>(rTestData); // setup - std::shared_ptr > spFilesystemMock(new StrictMock); + std::shared_ptr > spFilesystemMock(new NiceMock); EXPECT_CALL(*spFilesystemMock, PathExist(_)) - .Times(0); + .WillRepeatedly(Return(false)); // test execution TSmartPath pathResult = TransformPath(spFilesystemMock, @@ -93,5 +144,5 @@ bForceDirectories); // verification - EXPECT_STREQ(L"x:\\c", pathResult.ToString()); + ASSERT_STREQ(strExpectedResultPath.c_str(), pathResult.ToString()); }