[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:
Stefan Markovic
2022-08-24 12:04:23 +02:00
committed by GitHub
parent a3b7c70fe0
commit e7d3aadec3

View File

@@ -300,8 +300,11 @@ void cleanup_updates()
return; return;
} }
auto update_dir = updating::get_pending_updates_path();
if (std::filesystem::exists(update_dir))
{
// Msi and exe files // Msi and exe files
for (const auto& entry : std::filesystem::directory_iterator(updating::get_pending_updates_path())) for (const auto& entry : std::filesystem::directory_iterator(update_dir))
{ {
auto entryPath = entry.path().wstring(); auto entryPath = entry.path().wstring();
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower); std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
@@ -316,10 +319,13 @@ 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");
if (std::filesystem::exists(rootPath))
{
for (const auto& entry : std::filesystem::directory_iterator(rootPath)) for (const auto& entry : std::filesystem::directory_iterator(rootPath))
{ {
auto entryPath = entry.path().wstring(); auto entryPath = entry.path().wstring();
@@ -335,6 +341,7 @@ void cleanup_updates()
} }
} }
} }
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{ {