[Runner] Updates dir cleanup (#17893)

* updates dir cleanup

* improved code

* improved

* tweak comments
This commit is contained in:
Davide Giacometti 2022-04-27 21:24:03 +02:00 committed by GitHub
parent 7816c430a5
commit d74386acd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,14 +169,34 @@ bool InstallNewVersionStage2(std::wstring installer_path, std::wstring_view inst
}
}
for (const auto& entry : fs::directory_iterator(updating::get_pending_updates_path()))
{
auto entryPath = entry.path().wstring();
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
// Delete only .msi and .exe
if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
{
// Skipping current installer in case of failed update
if (installer_path.find(entryPath) != std::string::npos && !success)
{
continue;
}
std::error_code err;
fs::remove(entry, err);
if (err.value())
{
Logger::warn("Failed to delete file {}. {}", entry.path().string(), err.message());
}
}
}
if (!success)
{
return false;
}
std::error_code _;
fs::remove(installer_path, _);
UpdateState::store([&](UpdateState& state) {
state = {};
state.githubUpdateLastCheckedDate.emplace(timeutil::now());