mirror of https://github.com/mamba-org/mamba.git
Remove temp_file from public API (#3935)
This commit is contained in:
parent
31fb1fb90c
commit
5c838795ab
|
@ -8,7 +8,6 @@
|
||||||
#define MAMBA_CORE_SUBDIRDATA_HPP
|
#define MAMBA_CORE_SUBDIRDATA_HPP
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
@ -16,7 +15,6 @@
|
||||||
#include "mamba/core/error_handling.hpp"
|
#include "mamba/core/error_handling.hpp"
|
||||||
#include "mamba/core/package_cache.hpp"
|
#include "mamba/core/package_cache.hpp"
|
||||||
#include "mamba/core/subdir_parameters.hpp"
|
#include "mamba/core/subdir_parameters.hpp"
|
||||||
#include "mamba/core/util.hpp"
|
|
||||||
#include "mamba/download/downloader.hpp"
|
#include "mamba/download/downloader.hpp"
|
||||||
#include "mamba/download/parameters.hpp"
|
#include "mamba/download/parameters.hpp"
|
||||||
#include "mamba/fs/filesystem.hpp"
|
#include "mamba/fs/filesystem.hpp"
|
||||||
|
@ -197,7 +195,6 @@ namespace mamba
|
||||||
bool m_valid_cache_found = false;
|
bool m_valid_cache_found = false;
|
||||||
bool m_json_cache_valid = false;
|
bool m_json_cache_valid = false;
|
||||||
bool m_solv_cache_valid = false;
|
bool m_solv_cache_valid = false;
|
||||||
std::unique_ptr<TemporaryFile> m_temp_file;
|
|
||||||
|
|
||||||
SubdirData(
|
SubdirData(
|
||||||
const SubdirParams& params,
|
const SubdirParams& params,
|
||||||
|
@ -232,7 +229,8 @@ namespace mamba
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
auto use_existing_cache() -> expected_t<void>;
|
auto use_existing_cache() -> expected_t<void>;
|
||||||
auto finalize_transfer(SubdirMetadata::HttpMetadata http_data) -> expected_t<void>;
|
auto finalize_transfer(SubdirMetadata::HttpMetadata http_data, const fs::u8path& artifact)
|
||||||
|
-> expected_t<void>;
|
||||||
void refresh_last_write_time(const fs::u8path& json_file, const fs::u8path& solv_file);
|
void refresh_last_write_time(const fs::u8path& json_file, const fs::u8path& solv_file);
|
||||||
|
|
||||||
template <typename First, typename End>
|
template <typename First, typename End>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
// The full license is in the file LICENSE, distributed with this software.
|
// The full license is in the file LICENSE, distributed with this software.
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@
|
||||||
#include "mamba/core/package_cache.hpp"
|
#include "mamba/core/package_cache.hpp"
|
||||||
#include "mamba/core/subdirdata.hpp"
|
#include "mamba/core/subdirdata.hpp"
|
||||||
#include "mamba/core/thread_utils.hpp"
|
#include "mamba/core/thread_utils.hpp"
|
||||||
|
#include "mamba/core/util.hpp"
|
||||||
#include "mamba/fs/filesystem.hpp"
|
#include "mamba/fs/filesystem.hpp"
|
||||||
#include "mamba/specs/channel.hpp"
|
#include "mamba/specs/channel.hpp"
|
||||||
#include "mamba/util/cryptography.hpp"
|
#include "mamba/util/cryptography.hpp"
|
||||||
|
@ -748,7 +750,9 @@ namespace mamba
|
||||||
{
|
{
|
||||||
fs::u8path writable_cache_dir = create_cache_dir(m_writable_pkgs_dir);
|
fs::u8path writable_cache_dir = create_cache_dir(m_writable_pkgs_dir);
|
||||||
auto lock = LockFile(writable_cache_dir);
|
auto lock = LockFile(writable_cache_dir);
|
||||||
m_temp_file = std::make_unique<TemporaryFile>("mambaf", "", writable_cache_dir);
|
|
||||||
|
// TODO(C++23): Use std::make_unique when std::move_only_function is available
|
||||||
|
auto artifact = std::make_shared<TemporaryFile>("mambaf", "", writable_cache_dir);
|
||||||
|
|
||||||
bool use_zst = m_metadata.has_up_to_date_zst();
|
bool use_zst = m_metadata.has_up_to_date_zst();
|
||||||
|
|
||||||
|
@ -756,14 +760,14 @@ namespace mamba
|
||||||
name(),
|
name(),
|
||||||
download::MirrorName(channel_id()),
|
download::MirrorName(channel_id()),
|
||||||
repodata_url_path() + (use_zst ? ".zst" : ""),
|
repodata_url_path() + (use_zst ? ".zst" : ""),
|
||||||
m_temp_file->path().string(),
|
artifact->path().string(),
|
||||||
/*head_only*/ false,
|
/*head_only*/ false,
|
||||||
/*ignore_failure*/ !is_noarch()
|
/*ignore_failure*/ !is_noarch()
|
||||||
);
|
);
|
||||||
request.etag = m_metadata.etag();
|
request.etag = m_metadata.etag();
|
||||||
request.last_modified = m_metadata.last_modified();
|
request.last_modified = m_metadata.last_modified();
|
||||||
|
|
||||||
request.on_success = [this](const download::Success& success)
|
request.on_success = [this, artifact = std::move(artifact)](const download::Success& success)
|
||||||
{
|
{
|
||||||
if (success.transfer.http_status == 304)
|
if (success.transfer.http_status == 304)
|
||||||
{
|
{
|
||||||
|
@ -771,12 +775,15 @@ namespace mamba
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return finalize_transfer(SubdirMetadata::HttpMetadata{
|
return finalize_transfer(
|
||||||
repodata_url().str(),
|
SubdirMetadata::HttpMetadata{
|
||||||
success.etag,
|
repodata_url().str(),
|
||||||
success.last_modified,
|
success.etag,
|
||||||
success.cache_control,
|
success.last_modified,
|
||||||
});
|
success.cache_control,
|
||||||
|
},
|
||||||
|
artifact->path()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -844,12 +851,12 @@ namespace mamba
|
||||||
|
|
||||||
refresh_last_write_time(json_file, solv_file);
|
refresh_last_write_time(json_file, solv_file);
|
||||||
|
|
||||||
m_temp_file.reset();
|
|
||||||
m_valid_cache_found = true;
|
m_valid_cache_found = true;
|
||||||
return expected_t<void>();
|
return expected_t<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_t<void> SubdirData::finalize_transfer(SubdirMetadata::HttpMetadata http_data)
|
expected_t<void>
|
||||||
|
SubdirData::finalize_transfer(SubdirMetadata::HttpMetadata http_data, const fs::u8path& artifact)
|
||||||
{
|
{
|
||||||
if (m_writable_pkgs_dir.empty())
|
if (m_writable_pkgs_dir.empty())
|
||||||
{
|
{
|
||||||
|
@ -871,12 +878,12 @@ namespace mamba
|
||||||
fs::u8path state_file = json_file;
|
fs::u8path state_file = json_file;
|
||||||
state_file.replace_extension(".state.json");
|
state_file.replace_extension(".state.json");
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
mamba_fs::rename_or_move(m_temp_file->path(), json_file, ec);
|
mamba_fs::rename_or_move(artifact, json_file, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
std::string error = fmt::format(
|
std::string error = fmt::format(
|
||||||
"Could not move repodata file from {} to {}: {}",
|
"Could not move repodata file from {} to {}: {}",
|
||||||
m_temp_file->path(),
|
artifact,
|
||||||
json_file,
|
json_file,
|
||||||
strerror(errno)
|
strerror(errno)
|
||||||
);
|
);
|
||||||
|
@ -887,7 +894,6 @@ namespace mamba
|
||||||
m_metadata.store_file_metadata(json_file);
|
m_metadata.store_file_metadata(json_file);
|
||||||
m_metadata.write_state_file(state_file);
|
m_metadata.write_state_file(state_file);
|
||||||
|
|
||||||
m_temp_file.reset();
|
|
||||||
m_valid_cache_path = m_writable_pkgs_dir;
|
m_valid_cache_path = m_writable_pkgs_dir;
|
||||||
m_json_cache_valid = true;
|
m_json_cache_valid = true;
|
||||||
m_valid_cache_found = true;
|
m_valid_cache_found = true;
|
||||||
|
|
Loading…
Reference in New Issue