Skip to content

Commit

Permalink
OrcLib: Temporary: improve temporary folder deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
jgautier-anssi authored and fabienfl-orc committed Nov 9, 2020
1 parent 7a78990 commit 1862e0f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/OrcLib/Temporary.cpp
Expand Up @@ -12,6 +12,7 @@

#include "ParameterCheck.h"
#include "SecurityDescriptor.h"
#include "Output/Text/Fmt/error_code.h"

#include <boost/scope_exit.hpp>

Expand Down Expand Up @@ -606,16 +607,18 @@ HRESULT ORCLIB_API Orc::UtilDeleteTemporaryFile(LPCWSTR pszPath)

HRESULT ORCLIB_API Orc::UtilDeleteTemporaryDirectory(const std::filesystem::path& path)
{
for (auto& p : std::filesystem::directory_iterator(path))
for (auto& p : std::filesystem::recursive_directory_iterator(path))
{
if (auto hr = UtilDeleteTemporaryFile(p.path()); FAILED(hr))
Log::Error(L"Failed to delete temp file {} (hr:{:#010x})", p.path(), hr);
}

if (!RemoveDirectory(path.c_str()))
std::error_code ec;
std::filesystem::remove_all(path, ec);
if (ec)
{
Log::Error(L"Failed to delete temp dir {} (hr:{:#010x})", path, HRESULT_FROM_WIN32(GetLastError()));
return HRESULT_FROM_WIN32(GetLastError());
Log::Error(L"Failed to delete temp dir {} (ec:{})", path, ec);
return HRESULT_FROM_WIN32(ec.value());
}
return S_OK;
}
Expand Down

0 comments on commit 1862e0f

Please sign in to comment.