From ba660a3d11795f565036506feb4c0da3b252b1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Lamotte=20=28Klaim=29?= Date: Fri, 25 Mar 2022 12:06:42 +0100 Subject: [PATCH] fixes after rebase --- libmamba/CMakeLists.txt | 1 + .../include/mamba/core/error_handling.hpp | 1 - libmamba/include/mamba/core/util.hpp | 34 -------------- libmamba/include/mamba/core/util_scope.hpp | 45 +++++++++++++++++++ libmamba/src/core/env_lockfile.cpp | 1 + libmamba/src/core/transaction.cpp | 1 + libmamba/tests/test_util.cpp | 2 + 7 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 libmamba/include/mamba/core/util_scope.hpp diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index d44f7f8249..c32970fed5 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -162,6 +162,7 @@ set(LIBMAMBA_HEADERS ${LIBMAMBA_INCLUDE_DIR}/mamba/core/util.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_os.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_random.hpp + ${LIBMAMBA_INCLUDE_DIR}/mamba/core/util_scope.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/validate.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/virtual_packages.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/core/env_lockfile.hpp diff --git a/libmamba/include/mamba/core/error_handling.hpp b/libmamba/include/mamba/core/error_handling.hpp index 83a9b4ee0d..a14b8be76b 100644 --- a/libmamba/include/mamba/core/error_handling.hpp +++ b/libmamba/include/mamba/core/error_handling.hpp @@ -24,7 +24,6 @@ namespace mamba cache_not_loaded, repodata_not_loaded, configurable_bad_cast, - aggregated env_lockfile_parsing_failed, }; diff --git a/libmamba/include/mamba/core/util.hpp b/libmamba/include/mamba/core/util.hpp index a648e4ed06..e4df945c14 100644 --- a/libmamba/include/mamba/core/util.hpp +++ b/libmamba/include/mamba/core/util.hpp @@ -326,40 +326,6 @@ namespace mamba std::tuple, std::unique_ptr> prepare_wrapped_call( const fs::path& prefix, const std::vector& cmd); - - template - struct on_scope_exit - { - F func; - - explicit on_scope_exit(F&& f) - : func(std::forward(f)) - { - } - - ~on_scope_exit() - { - try - { - func(); - } - catch (const std::exception& ex) - { - LOG_ERROR << fmt::format("Scope exit error (catched and ignored): {}", ex.what()); - } - catch (...) - { - LOG_ERROR << "Scope exit unknown error (catched and ignored)"; - } - } - - // Deactivate copy & move until we implement moves - on_scope_exit(const on_scope_exit&) = delete; - on_scope_exit& operator=(const on_scope_exit&) = delete; - on_scope_exit(on_scope_exit&&) = delete; - on_scope_exit& operator=(on_scope_exit&&) = delete; - }; - /// Returns `true` if the filename matches names of files which should be interpreted as YAML. /// NOTE: this does not check if the file exists. inline bool is_yaml_file_name(const std::string_view filename) diff --git a/libmamba/include/mamba/core/util_scope.hpp b/libmamba/include/mamba/core/util_scope.hpp new file mode 100644 index 0000000000..46796b803d --- /dev/null +++ b/libmamba/include/mamba/core/util_scope.hpp @@ -0,0 +1,45 @@ + +#ifndef MAMBA_CORE_UTIL_SCOPE_HPP +#define MAMBA_CORE_UTIL_SCOPE_HPP + +#include +#include "mamba/core/output.hpp" + +namespace mamba +{ + + template + struct on_scope_exit + { + F func; + + explicit on_scope_exit(F&& f) + : func(std::forward(f)) + { + } + + ~on_scope_exit() + { + try + { + func(); + } + catch (const std::exception& ex) + { + LOG_ERROR << fmt::format("Scope exit error (catched and ignored): {}", ex.what()); + } + catch (...) + { + LOG_ERROR << "Scope exit unknown error (catched and ignored)"; + } + } + + // Deactivate copy & move until we implement moves + on_scope_exit(const on_scope_exit&) = delete; + on_scope_exit& operator=(const on_scope_exit&) = delete; + on_scope_exit(on_scope_exit&&) = delete; + on_scope_exit& operator=(on_scope_exit&&) = delete; + }; +} + +#endif diff --git a/libmamba/src/core/env_lockfile.cpp b/libmamba/src/core/env_lockfile.cpp index 2e193ebabe..0f742bca02 100644 --- a/libmamba/src/core/env_lockfile.cpp +++ b/libmamba/src/core/env_lockfile.cpp @@ -7,6 +7,7 @@ #include "mamba/core/env_lockfile.hpp" #include +#include "mamba/core/output.hpp" #include "mamba/core/match_spec.hpp" diff --git a/libmamba/src/core/transaction.cpp b/libmamba/src/core/transaction.cpp index 9d36d3a61d..edf94ca3b3 100644 --- a/libmamba/src/core/transaction.cpp +++ b/libmamba/src/core/transaction.cpp @@ -15,6 +15,7 @@ #include "mamba/core/output.hpp" #include "mamba/core/pool.hpp" #include "mamba/core/thread_utils.hpp" +#include "mamba/core/util_scope.hpp" #include "termcolor/termcolor.hpp" diff --git a/libmamba/tests/test_util.cpp b/libmamba/tests/test_util.cpp index 978d20bb94..037a61150a 100644 --- a/libmamba/tests/test_util.cpp +++ b/libmamba/tests/test_util.cpp @@ -4,6 +4,8 @@ #include "mamba/core/util.hpp" #include "mamba/core/util_random.hpp" +#include "mamba/core/util_scope.hpp" + namespace mamba {