From 8f70359fb55025cd00ee08fa7167b83fd501e55f Mon Sep 17 00:00:00 2001 From: Ruchika Mittal Date: Mon, 25 Sep 2023 03:30:28 -0400 Subject: [PATCH] added test case.. Change-Id: Iea39f1637a5f42304622bbb9a6d831b2568c16ac --- libmamba/include/mamba/core/util_os.hpp | 3 --- libmamba/src/core/link.cpp | 16 +++++++++++----- libmamba/src/core/util_os.cpp | 19 ------------------- micromamba/tests/test_linking.py | 2 ++ 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/libmamba/include/mamba/core/util_os.hpp b/libmamba/include/mamba/core/util_os.hpp index b82f2fcdb4..7e1049a1d0 100644 --- a/libmamba/include/mamba/core/util_os.hpp +++ b/libmamba/include/mamba/core/util_os.hpp @@ -67,9 +67,6 @@ namespace mamba void codesign(const fs::u8path& path, bool verbose = false); std::string fix_win_path(const std::string& path); -#ifndef _WIN32 - bool is_executable(const fs::u8path& path); -#endif } #endif diff --git a/libmamba/src/core/link.cpp b/libmamba/src/core/link.cpp index 39aeae7ac0..5b394301ee 100644 --- a/libmamba/src/core/link.cpp +++ b/libmamba/src/core/link.cpp @@ -753,8 +753,7 @@ namespace mamba { bool copy = path_data.no_link || m_context->always_copy; bool softlink = m_context->always_softlink; - - if ((!copy && !softlink) || is_executable(src)) + if (!copy && !softlink) { std::error_code lec; fs::create_hard_link(src, dst, lec); @@ -789,15 +788,22 @@ namespace mamba try { fs::copy(src, dst); + LOG_TRACE << "copied '" << src.string() << "'" << std::endl + << " --> '" << dst.string() << "'"; } catch (const std::filesystem::filesystem_error& ex) { Console::stream() << "could not copy: " << src.string() << " -> " << dst.string() << ": " << ex.what(); + if (fs::exists(dst)) + { + LOG_TRACE << dst.string() << " already exists" << std::endl; + } + else + { + throw ex; + } } - - LOG_TRACE << "copied '" << src.string() << "'" << std::endl - << " --> '" << dst.string() << "'"; } } else if (path_data.path_type == PathType::SOFTLINK) diff --git a/libmamba/src/core/util_os.cpp b/libmamba/src/core/util_os.cpp index 4faddeca06..dba020b3cc 100644 --- a/libmamba/src/core/util_os.cpp +++ b/libmamba/src/core/util_os.cpp @@ -705,23 +705,4 @@ namespace mamba return path; #endif } - -#ifndef _WIN32 - bool is_executable(const fs::u8path& path) - { - struct stat sb; - bool rc = false; - if (stat(path.string().c_str(), &sb) != 0) - { - return rc; - } - - if (sb.st_mode & S_IXUSR) - { - rc = true; - } - return rc; - } -#endif - } diff --git a/micromamba/tests/test_linking.py b/micromamba/tests/test_linking.py index 2a54c2e3cb..7f99a01dce 100644 --- a/micromamba/tests/test_linking.py +++ b/micromamba/tests/test_linking.py @@ -77,6 +77,7 @@ def test_copy(self, existing_cache, test_pkg): def test_always_softlink(self, existing_cache, test_pkg): create( "xtensor", + "r-base", "-n", TestLinking.env_name, "--json", @@ -101,6 +102,7 @@ def test_cross_device(self, allow_softlinks, always_copy, existing_cache, test_p pytest.skip("o/s is not linux") create_args = ["xtensor", "-n", TestLinking.env_name, "--json"] + if allow_softlinks: create_args.append("--allow-softlinks") if always_copy: