From ee6c571e8d7879e4b8eab9222c3518fbbe7f750f Mon Sep 17 00:00:00 2001 From: Jean Gautier Date: Mon, 19 Oct 2020 11:25:43 +0200 Subject: [PATCH] OrcLib: Temporary: add UtilDeleteTemporaryDirectory Added for Flashback. --- src/OrcLib/Temporary.cpp | 21 +++++++++++++++++++++ src/OrcLib/Temporary.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/OrcLib/Temporary.cpp b/src/OrcLib/Temporary.cpp index 7ce0575a..c026bf6f 100644 --- a/src/OrcLib/Temporary.cpp +++ b/src/OrcLib/Temporary.cpp @@ -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; diff --git a/src/OrcLib/Temporary.h b/src/OrcLib/Temporary.h index bed7e15b..48fae212 100644 --- a/src/OrcLib/Temporary.h +++ b/src/OrcLib/Temporary.h @@ -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;