From 3bf72b6dcbc20bc7012306aa1b0fcfd6feb0e159 Mon Sep 17 00:00:00 2001 From: Luc Guyot Date: Thu, 31 Oct 2024 17:37:05 +0100 Subject: [PATCH] Remove code duplication by the re-use of the CommonUtility helpers --- extensions/windows/cfapi/Common/utilities.cpp | 21 +++++-------------- src/libcommon/utility/utility.h | 1 - 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/extensions/windows/cfapi/Common/utilities.cpp b/extensions/windows/cfapi/Common/utilities.cpp index 333a50b3b..e6f2ab611 100644 --- a/extensions/windows/cfapi/Common/utilities.cpp +++ b/extensions/windows/cfapi/Common/utilities.cpp @@ -18,11 +18,12 @@ #include "utilities.h" +#include "../../../../src/libcommon/utility/utility.h" + #include #include #include -#include #include #define PIPE_TIMEOUT 5 * 1000 // ms @@ -326,18 +327,6 @@ bool Utilities::readNextValue(std::wstring &message, std::wstring &value) { return true; } -namespace { - -bool isLikeFileNotFoundError(DWORD dwError) noexcept { - return (dwError != ERROR_FILE_NOT_FOUND) && (dwError != ERROR_PATH_NOT_FOUND) && (dwError != ERROR_INVALID_DRIVE) && - (dwError != ERROR_BAD_NETPATH); -} - -bool isLikeFileNotFoundError(const std::error_code &code) noexcept { - return isLikeFileNotFoundError(static_cast(code.value())); -} -} // namespace - std::wstring Utilities::getLastErrorMessage() { const DWORD errorMessageID = ::GetLastError(); if (errorMessageID == 0) return {}; @@ -365,7 +354,7 @@ bool Utilities::checkIfIsLink(const wchar_t *path, bool &isSymlink, bool &isJunc HANDLE hFile = CreateFileW(path, FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); if (hFile == INVALID_HANDLE_VALUE) { - exists = isLikeFileNotFoundError(GetLastError()); + exists = KDC::CommonUtility::isLikeFileNotFoundError(GetLastError()); return !exists; } @@ -381,7 +370,7 @@ bool Utilities::checkIfIsLink(const wchar_t *path, bool &isSymlink, bool &isJunc return true; } - exists = isLikeFileNotFoundError(GetLastError()); + exists = KDC::CommonUtility::isLikeFileNotFoundError(GetLastError()); return !exists; } @@ -399,7 +388,7 @@ bool Utilities::checkIfIsDirectory(const wchar_t *path, bool &isDirectory, bool std::error_code ec; isDirectory = std::filesystem::is_directory(std::filesystem::path(path), ec); if (!isDirectory && ec.value() != 0) { - exists = isLikeFileNotFoundError(ec); + exists = KDC::CommonUtility::isLikeFileNotFoundError(ec); if (!exists) { return true; } diff --git a/src/libcommon/utility/utility.h b/src/libcommon/utility/utility.h index ac881a0ba..3ebeab650 100644 --- a/src/libcommon/utility/utility.h +++ b/src/libcommon/utility/utility.h @@ -20,7 +20,6 @@ #include "libcommon/libcommon.h" #include "types.h" -#include "libcommon/info/nodeinfo.h" #include