Skip to content

Commit

Permalink
OrcLib: Temporary: add UtilDeleteTemporaryDirectory
Browse files Browse the repository at this point in the history
Added for Flashback.
  • Loading branch information
jgautier-anssi authored and fabienfl-orc committed Nov 9, 2020
1 parent b65d734 commit ee6c571
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/OrcLib/Temporary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,27 @@ HRESULT ORCLIB_API Orc::UtilDeleteTemporaryFile(LPCWSTR pszPath)
return S_OK;
}

HRESULT ORCLIB_API Orc::UtilDeleteTemporaryDirectory(const std::filesystem::path& path)
{
for (auto& p : std::filesystem::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()))
{
Log::Error(L"Failed to delete temp dir {} (hr:{:#010x})", path, HRESULT_FROM_WIN32(GetLastError()));
return HRESULT_FROM_WIN32(GetLastError());
}
return S_OK;
}

HRESULT ORCLIB_API Orc::UtilDeleteTemporaryFile(const std::filesystem::path& path)
{
return UtilDeleteTemporaryFile(path.c_str());
}

HRESULT ORCLIB_API Orc::UtilDeleteTemporaryFile(__in LPCWSTR pszPath, DWORD dwMaxRetries)
{
HRESULT hr = E_FAIL;
Expand Down
3 changes: 3 additions & 0 deletions src/OrcLib/Temporary.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ HRESULT ORCLIB_API UtilGetPath(__in PCWSTR pwzDir, __in PCWSTR pwzDesiredName, _
BOOL ORCLIB_API UtilPathIsDirectory(__in PCWSTR pwszPath);

HRESULT ORCLIB_API UtilDeleteTemporaryFile(LPCWSTR pszPath);
HRESULT ORCLIB_API UtilDeleteTemporaryFile(const std::filesystem::path& path);

HRESULT ORCLIB_API UtilDeleteTemporaryDirectory(const std::filesystem::path& path);

static constexpr auto DELETION_RETRIES = 50;

Expand Down

0 comments on commit ee6c571

Please sign in to comment.