Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaim committed Mar 25, 2022
1 parent 9c5adf4 commit ba660a3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
1 change: 1 addition & 0 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion libmamba/include/mamba/core/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace mamba
cache_not_loaded,
repodata_not_loaded,
configurable_bad_cast,
aggregated
env_lockfile_parsing_failed,
};

Expand Down
34 changes: 0 additions & 34 deletions libmamba/include/mamba/core/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,40 +326,6 @@ namespace mamba
std::tuple<std::vector<std::string>, std::unique_ptr<TemporaryFile>> prepare_wrapped_call(
const fs::path& prefix, const std::vector<std::string>& cmd);


template <typename F>
struct on_scope_exit
{
F func;

explicit on_scope_exit(F&& f)
: func(std::forward<F>(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)
Expand Down
45 changes: 45 additions & 0 deletions libmamba/include/mamba/core/util_scope.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

#ifndef MAMBA_CORE_UTIL_SCOPE_HPP
#define MAMBA_CORE_UTIL_SCOPE_HPP

#include <stdexcept>
#include "mamba/core/output.hpp"

namespace mamba
{

template <typename F>
struct on_scope_exit
{
F func;

explicit on_scope_exit(F&& f)
: func(std::forward<F>(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
1 change: 1 addition & 0 deletions libmamba/src/core/env_lockfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mamba/core/env_lockfile.hpp"

#include <yaml-cpp/yaml.h>
#include "mamba/core/output.hpp"

#include "mamba/core/match_spec.hpp"

Expand Down
1 change: 1 addition & 0 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions libmamba/tests/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "mamba/core/util.hpp"
#include "mamba/core/util_random.hpp"
#include "mamba/core/util_scope.hpp"


namespace mamba
{
Expand Down

0 comments on commit ba660a3

Please sign in to comment.