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

Remove MSIX installers after validation is done #2591

Merged
merged 6 commits into from
Oct 12, 2022
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
23 changes: 17 additions & 6 deletions src/AppInstallerCommonCore/Manifest/MsixManifestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (...)
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down