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;