fix: Remove invalid cached tarballs (#3839)

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Klaim <Klaim@users.noreply.github.com>
This commit is contained in:
Julien Jerphanion 2025-03-05 12:20:21 +01:00 committed by GitHub
parent 04b2f2cae3
commit e5004266cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

View File

@ -5,6 +5,7 @@
// The full license is in the file LICENSE, distributed with this software.
#include <fstream>
#include <sstream>
#include <nlohmann/json.hpp>
@ -168,7 +169,38 @@ namespace mamba
}
else
{
LOG_WARNING << "Package tarball '" << tarball_path.string() << "' is invalid";
std::stringstream msg;
msg << "Package tarball '" << tarball_path.string() << "' is invalid.\n";
if (s.size != 0)
{
msg << " - Expected size : " << s.size << "\n"
<< " - Effective size : " << fs::file_size(tarball_path) << "\n";
}
if (!s.md5.empty())
{
msg << " - Expected md5 : " << s.md5 << "\n"
<< " - Effective md5 : " << validation::md5sum(tarball_path) << "\n";
}
if (!s.sha256.empty())
{
msg << " - Expected sha256 : " << s.sha256 << "\n"
<< " - Effective sha256 : " << validation::sha256sum(tarball_path) << "\n";
}
msg << "Deleting '" << tarball_path.string() << "'";
LOG_TRACE << msg.str();
std::error_code ec;
fs::remove(tarball_path, ec);
if (ec)
{
LOG_ERROR << "Failed to remove invalid tarball '" << tarball_path.string()
<< "' (error_code: " << ec.message() << ")";
}
else
{
LOG_TRACE << "Package tarball '" << tarball_path.string() << "' removed";
}
}
m_valid_tarballs[pkg] = valid;
}

View File

@ -162,7 +162,11 @@ namespace mamba
{
LOG_ERROR << "Failed to download package from "
<< error.transfer.value().effective_url << " (status "
<< error.transfer.value().http_status << ")";
<< error.transfer.value().http_status << ")\n"
<< "If you see this message repeatedly, the state of your installation might be corrupted,\n"
<< "in which case running `mamba clean --all` might fix it.\n\n"
<< "If you continue to meet this problem, please search or report an issue\n"
<< "on mamba's issue tracker: https://github.com/mamba-org/mamba/issues/";
}
else
{