mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 02:09:24 +08:00
Make delete_other_versions_log_folders more reliable (#10760)
This commit is contained in:
parent
71cf94b330
commit
6e65f9cbd5
@ -28,13 +28,40 @@ namespace LoggerHelpers
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool dir_exists(std::filesystem::path dir)
|
||||
{
|
||||
std::error_code err;
|
||||
auto entry = std::filesystem::directory_entry(dir, err);
|
||||
if (err.value())
|
||||
{
|
||||
Logger::error("Failed to create directory entry. {}", err.message());
|
||||
return false;
|
||||
}
|
||||
|
||||
return entry.exists();
|
||||
}
|
||||
|
||||
inline bool delete_other_versions_log_folders(std::wstring_view appPath, const std::filesystem::path& currentVersionLogFolder)
|
||||
{
|
||||
bool result = true;
|
||||
std::filesystem::path logFolderPath(appPath);
|
||||
logFolderPath.append(LogSettings::logPath);
|
||||
|
||||
for (const auto& dir : std::filesystem::directory_iterator(logFolderPath))
|
||||
if (!dir_exists(logFolderPath))
|
||||
{
|
||||
Logger::trace("Directory {} does not exist", logFolderPath.string());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::error_code err;
|
||||
auto folders = std::filesystem::directory_iterator(logFolderPath, err);
|
||||
if (err.value())
|
||||
{
|
||||
Logger::error("Failed to create directory iterator for {}. {}", logFolderPath.string(), err.message());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& dir : folders)
|
||||
{
|
||||
if (dir != currentVersionLogFolder)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user