Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the transaction.hpp header #2564

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ set(LIBMAMBA_SOURCES
${LIBMAMBA_SOURCE_DIR}/core/subdirdata.cpp
${LIBMAMBA_SOURCE_DIR}/core/thread_utils.cpp
${LIBMAMBA_SOURCE_DIR}/core/transaction.cpp
${LIBMAMBA_SOURCE_DIR}/core/package_download.cpp
${LIBMAMBA_SOURCE_DIR}/core/util.cpp
${LIBMAMBA_SOURCE_DIR}/core/fsutil.cpp
${LIBMAMBA_SOURCE_DIR}/core/util_string.cpp
Expand Down Expand Up @@ -238,6 +239,7 @@ set(LIBMAMBA_PUBLIC_HEADERS
${LIBMAMBA_INCLUDE_DIR}/mamba/core/solver.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/subdirdata.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/thread_utils.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/package_download.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/transaction.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/transaction_context.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/core/url.hpp
Expand Down
99 changes: 99 additions & 0 deletions libmamba/include/mamba/core/package_download.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) 2023, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.


#ifndef MAMBA_CORE_PACKAGE_DOWNLOAD_HPP
#define MAMBA_CORE_PACKAGE_DOWNLOAD_HPP

#include <future>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#include "fetch.hpp"
#include "mamba_fs.hpp"
#include "package_cache.hpp"
#include "progress_bar.hpp"
#include "thread_utils.hpp"

namespace mamba
{
class ChannelContext;

class PackageDownloadExtractTarget
{
public:

enum VALIDATION_RESULT
{
UNDEFINED = 0,
VALID = 1,
SHA256_ERROR,
MD5SUM_ERROR,
SIZE_ERROR,
EXTRACT_ERROR
};

PackageDownloadExtractTarget(const PackageInfo& pkg_info, ChannelContext& channel_context);

void write_repodata_record(const fs::u8path& base_path);
void add_url();
bool finalize_callback(const DownloadTarget& target);
bool finished();
void validate();
bool extract();
bool extract_from_cache();
bool validate_extract();
const std::string& name() const;
std::size_t expected_size() const;
VALIDATION_RESULT validation_result() const;
void clear_cache() const;

DownloadTarget* target(MultiPackageCache& cache);

std::exception m_decompress_exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW do you know what this object is and why it's public?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not yet worked with that code.
M guess is catching the exception is thread to rethrow in the main one.


private:

bool m_finished;
PackageInfo m_package_info;

std::string m_sha256, m_md5;
std::size_t m_expected_size;

bool m_has_progress_bars = false;
ProgressProxy m_download_bar, m_extract_bar;
std::unique_ptr<DownloadTarget> m_target;

std::string m_url, m_name, m_filename;
fs::u8path m_tarball_path, m_cache_path;

std::future<bool> m_extract_future;

VALIDATION_RESULT m_validation_result = VALIDATION_RESULT::UNDEFINED;

std::function<void(ProgressBarRepr&)> extract_repr();
std::function<void(ProgressProxy&)> extract_progress_callback();
};

class DownloadExtractSemaphore
{
public:

static std::ptrdiff_t get_max();
static void set_max(int value);

private:

static counting_semaphore semaphore;

friend class PackageDownloadExtractTarget;
};
} // namespace mamba

#endif
79 changes: 0 additions & 79 deletions libmamba/include/mamba/core/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,106 +7,27 @@
#ifndef MAMBA_CORE_TRANSACTION_HPP
#define MAMBA_CORE_TRANSACTION_HPP

#include <future>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#include <nlohmann/json.hpp>
#include <solv/transaction.h>

#include "mamba/api/install.hpp"

#include "env_lockfile.hpp"
#include "fetch.hpp"
#include "mamba_fs.hpp"
#include "match_spec.hpp"
#include "package_cache.hpp"
#include "package_handling.hpp"
#include "prefix_data.hpp"
#include "progress_bar.hpp"
#include "repo.hpp"
#include "solver.hpp"
#include "thread_utils.hpp"
#include "transaction_context.hpp"


namespace mamba
{
class ChannelContext;

class PackageDownloadExtractTarget
{
public:

PackageDownloadExtractTarget(const PackageInfo& pkg_info, ChannelContext& channel_context);

void write_repodata_record(const fs::u8path& base_path);
void add_url();
bool finalize_callback(const DownloadTarget& target);
bool finished();
void validate();
bool extract();
bool extract_from_cache();
bool validate_extract();
const std::string& name() const;
std::size_t expected_size() const;
auto validation_result() const;
void clear_cache() const;

DownloadTarget* target(MultiPackageCache& cache);

enum VALIDATION_RESULT
{
UNDEFINED = 0,
VALID = 1,
SHA256_ERROR,
MD5SUM_ERROR,
SIZE_ERROR,
EXTRACT_ERROR
};

std::exception m_decompress_exception;

private:

bool m_finished;
PackageInfo m_package_info;

std::string m_sha256, m_md5;
std::size_t m_expected_size;

bool m_has_progress_bars = false;
ProgressProxy m_download_bar, m_extract_bar;
std::unique_ptr<DownloadTarget> m_target;

std::string m_url, m_name, m_filename;
fs::u8path m_tarball_path, m_cache_path;

std::future<bool> m_extract_future;

VALIDATION_RESULT m_validation_result = VALIDATION_RESULT::UNDEFINED;

std::function<void(ProgressBarRepr&)> extract_repr();
std::function<void(ProgressProxy&)> extract_progress_callback();
};

class DownloadExtractSemaphore
{
public:

static std::ptrdiff_t get_max();
static void set_max(int value);

private:

static counting_semaphore semaphore;

friend class PackageDownloadExtractTarget;
};

class MTransaction
{
public:
Expand Down
3 changes: 1 addition & 2 deletions libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include "mamba/core/environment.hpp"
#include "mamba/core/fsutil.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/url.hpp"
#include "mamba/core/package_download.hpp"

namespace mamba
{
Expand Down
1 change: 1 addition & 0 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/package_download.hpp"
#include "mamba/core/pinning.hpp"
#include "mamba/core/transaction.hpp"
#include "mamba/core/util_string.hpp"
Expand Down
Loading