mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 12:46:47 +02:00
[runner]Fix issue on files cleanup when directory doesn't exist (#20063)
* Fix issue when directory doesn't exist * Address PR comment
This commit is contained in:
@@ -300,19 +300,23 @@ void cleanup_updates()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Msi and exe files
|
auto update_dir = updating::get_pending_updates_path();
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(updating::get_pending_updates_path()))
|
if (std::filesystem::exists(update_dir))
|
||||||
{
|
{
|
||||||
auto entryPath = entry.path().wstring();
|
// Msi and exe files
|
||||||
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
for (const auto& entry : std::filesystem::directory_iterator(update_dir))
|
||||||
|
|
||||||
if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
|
|
||||||
{
|
{
|
||||||
std::error_code err;
|
auto entryPath = entry.path().wstring();
|
||||||
std::filesystem::remove(entry, err);
|
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
||||||
if (err.value())
|
|
||||||
|
if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
|
||||||
{
|
{
|
||||||
Logger::warn("Failed to delete installer file {}. {}", entry.path().string(), err.message());
|
std::error_code err;
|
||||||
|
std::filesystem::remove(entry, err);
|
||||||
|
if (err.value())
|
||||||
|
{
|
||||||
|
Logger::warn("Failed to delete installer file {}. {}", entry.path().string(), err.message());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,17 +324,20 @@ void cleanup_updates()
|
|||||||
// Log files
|
// Log files
|
||||||
auto rootPath{ PTSettingsHelper::get_root_save_folder_location() };
|
auto rootPath{ PTSettingsHelper::get_root_save_folder_location() };
|
||||||
auto currentVersion = left_trim<wchar_t>(get_product_version(), L"v");
|
auto currentVersion = left_trim<wchar_t>(get_product_version(), L"v");
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(rootPath))
|
if (std::filesystem::exists(rootPath))
|
||||||
{
|
{
|
||||||
auto entryPath = entry.path().wstring();
|
for (const auto& entry : std::filesystem::directory_iterator(rootPath))
|
||||||
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
|
||||||
if (entry.is_regular_file() && entryPath.ends_with(L".log") && entryPath.find(currentVersion) == std::string::npos)
|
|
||||||
{
|
{
|
||||||
std::error_code err;
|
auto entryPath = entry.path().wstring();
|
||||||
std::filesystem::remove(entry, err);
|
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
||||||
if (err.value())
|
if (entry.is_regular_file() && entryPath.ends_with(L".log") && entryPath.find(currentVersion) == std::string::npos)
|
||||||
{
|
{
|
||||||
Logger::warn("Failed to delete log file {}. {}", entry.path().string(), err.message());
|
std::error_code err;
|
||||||
|
std::filesystem::remove(entry, err);
|
||||||
|
if (err.value())
|
||||||
|
{
|
||||||
|
Logger::warn("Failed to delete log file {}. {}", entry.path().string(), err.message());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user