winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0d42e2651ac919ab3ab4b29a10710d6fd5439353
parent 878fcdc66041e48ccfc0bdf0c87cb32126ca32ea
Author: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com>
Date:   Wed, 12 Oct 2022 10:27:39 -0700

Remove MSIX installers after validation is done (#2591)


Diffstat:
Msrc/AppInstallerCommonCore/Manifest/MsixManifestValidation.cpp | 23+++++++++++++++++------
Msrc/AppInstallerCommonCore/Public/winget/MsixManifestValidation.h | 3+++
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/AppInstallerCommonCore/Manifest/MsixManifestValidation.cpp b/src/AppInstallerCommonCore/Manifest/MsixManifestValidation.cpp @@ -36,6 +36,22 @@ namespace AppInstaller::Manifest return errors; } + MsixManifestValidation::~MsixManifestValidation() + { + AICLI_LOG(Core, Info, << "Removing downloaded installers"); + for (const auto& installerPath : m_downloadedInstallers) + { + try + { + std::filesystem::remove(installerPath); + } + catch (...) + { + AICLI_LOG(Core, Warning, << "Failed to remove downloaded installer: " << installerPath); + } + } + } + std::optional<std::filesystem::path> MsixManifestValidation::DownloadInstaller(std::string installerUrl, int retryCount) { while (retryCount-- > 0) @@ -46,6 +62,7 @@ namespace AppInstaller::Manifest auto tempFile = Runtime::GetNewTempFilePath(); ProgressCallback callback; Utility::Download(installerUrl, tempFile, Utility::DownloadType::Installer, callback); + m_downloadedInstallers.push_back(tempFile); return tempFile; } catch (...) @@ -87,12 +104,6 @@ namespace AppInstaller::Manifest { AICLI_LOG(Core, Error, << "Error fetching Msix info from the installer local path."); } - - AICLI_LOG(Core, Info, << "Removing downloaded installer"); - if (!std::filesystem::remove(installerPath.value())) - { - AICLI_LOG(Core, Warning, << "Failed to remove downloaded installer"); - } } else { diff --git a/src/AppInstallerCommonCore/Public/winget/MsixManifestValidation.h b/src/AppInstallerCommonCore/Public/winget/MsixManifestValidation.h @@ -12,12 +12,15 @@ namespace AppInstaller::Manifest { MsixManifestValidation(ValidationError::Level validationErrorLevel) : m_validationErrorLevel(validationErrorLevel) {} + ~MsixManifestValidation(); + // Validate manifest for Msix packages and Msix bundles. std::vector<ValidationError> Validate( const Manifest &manifest, const ManifestInstaller &installer); private: std::map<std::string, std::shared_ptr<Msix::MsixInfo>> m_msixInfoCache; + std::vector<std::filesystem::path> m_downloadedInstallers; ValidationError::Level m_validationErrorLevel; // Get Msix info from url/local path, or load it from cache.