From 78319557792058a5d5f2a213e301dcab62af3c68 Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Thu, 2 May 2019 06:43:33 +0200 Subject: [PATCH] Fix CE GitOrigin-RevId: 1747b786d930cd2150a9d5eacd75908e3f37a45b --- tdutils/td/utils/port/path.cpp | 23 ++++++++++++----------- tdutils/test/port.cpp | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 3c4e2c54..b5d05ebf 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -549,15 +549,6 @@ Result> mkstemp(CSlice dir) { static Result walk_path_dir(const std::wstring &dir_name, const std::function &func) { std::wstring name = dir_name + L"\\*"; - switch (func(entry_name, WalkPath::Type::EnterDir)) { - case WalkPath::Action::Abort: - return false; - case WalkPath::Action::SkipDir: - return true; - case WalkPath::Action::Continue: - break; - } - WIN32_FIND_DATA file_data; auto handle = FindFirstFileExW(name.c_str(), FindExInfoStandard, &file_data, FindExSearchNameMatch, nullptr, 0); if (handle == INVALID_HANDLE_VALUE) { @@ -567,6 +558,17 @@ static Result walk_path_dir(const std::wstring &dir_name, SCOPE_EXIT { FindClose(handle); }; + + TRY_RESULT(dir_entry_name, from_wstring(dir_name)); + switch (func(dir_entry_name, WalkPath::Type::EnterDir)) { + case WalkPath::Action::Abort: + return false; + case WalkPath::Action::SkipDir: + return true; + case WalkPath::Action::Continue: + break; + } + while (true) { auto full_name = dir_name + L"\\" + file_data.cFileName; TRY_RESULT(entry_name, from_wstring(full_name)); @@ -595,8 +597,7 @@ static Result walk_path_dir(const std::wstring &dir_name, return OS_ERROR("FindNextFileW"); } } - TRY_RESULT(entry_name, from_wstring(dir_name)); - switch (func(entry_name, WalkPath::Type::ExitDir)) { + switch (func(dir_entry_name, WalkPath::Type::ExitDir)) { case WalkPath::Action::Abort: return false; case WalkPath::Action::SkipDir: diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index 9a2550d0..231f539b 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -46,7 +46,7 @@ TEST(Port, files) { bool was_abort = false; walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { CHECK(!was_abort); - if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << "/B")) { + if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << TD_DIR_SLASH << "B")) { was_abort = true; return WalkPath::Action::Abort; }