From 67b1cce74efd5c7c4d8a8adf92d8f4a5aa920417 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Mar 2018 22:37:31 +0300 Subject: [PATCH] Support ignore_access_denied in realpath on Window. GitOrigin-RevId: 4fed501fee67b8533920fd729f1aa1944642db60 --- tdutils/td/utils/port/path.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 1c25c82d..9cd431cf 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -231,14 +231,21 @@ Status rename(CSlice from, CSlice to) { return Status::OK(); } -Result realpath(CSlice slice, bool /*ignore_access_denied*/) { +Result realpath(CSlice slice, bool ignore_access_denied) { wchar_t buf[MAX_PATH + 1]; TRY_RESULT(wslice, to_wstring(slice)); auto status = GetFullPathNameW(wslice.c_str(), MAX_PATH, buf, nullptr); + string res; if (status == 0) { - return OS_ERROR(PSLICE() << "GetFullPathNameW failed for \"" << slice << '"'); + if (ignore_access_denied && errno == ERROR_ACCESS_DENIED) { + res = slice.str(); + } else { + return OS_ERROR(PSLICE() << "GetFullPathNameW failed for \"" << slice << '"'); + } + } else { + TRY_RESULT(t_res, from_wstring(buf)); + res = std::move(t_res); } - TRY_RESULT(res, from_wstring(buf)); if (res.empty()) { return Status::Error("Empty path"); }