Skip to content

Commit

Permalink
[Runner] Updates dir cleanup (microsoft#17893)
Browse files Browse the repository at this point in the history
* updates dir cleanup

* improved code

* improved

* tweak comments
  • Loading branch information
davidegiacometti authored Apr 27, 2022
1 parent 7816c43 commit d74386a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Update/PowerToys.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d74386a

Please sign in to comment.