Skip to content

Commit

Permalink
Remove code duplication by the re-use of the CommonUtility helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-guyot-infomaniak committed Nov 19, 2024
1 parent 5790f01 commit 3bf72b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
21 changes: 5 additions & 16 deletions extensions/windows/cfapi/Common/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

#include "utilities.h"

#include "../../../../src/libcommon/utility/utility.h"

#include <winrt\base.h>

#include <vector>
#include <array>
#include <regex>
#include <filesystem>

#define PIPE_TIMEOUT 5 * 1000 // ms
Expand Down Expand Up @@ -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<DWORD>(code.value()));
}
} // namespace

std::wstring Utilities::getLastErrorMessage() {
const DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0) return {};
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/libcommon/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "libcommon/libcommon.h"
#include "types.h"
#include "libcommon/info/nodeinfo.h"

#include <string>

Expand Down

0 comments on commit 3bf72b6

Please sign in to comment.