diff --git a/tdutils/td/utils/port/path.h b/tdutils/td/utils/port/path.h index 47b7d3a3..727ee173 100644 --- a/tdutils/td/utils/port/path.h +++ b/tdutils/td/utils/port/path.h @@ -212,11 +212,12 @@ Status walk_path_dir(const std::wstring &dir_name, Func &&func) { template Status walk_path(CSlice path, Func &&func) { + TRY_RESULT(wpath, to_wstring(path)); Slice path_slice = path; while (!path_slice.empty() && (path_slice.back() == '/' || path_slice.back() == '\\')) { path_slice.remove_suffix(1); + wpath.pop_back(); } - TRY_RESULT(wpath, to_wstring(path_slice)); return detail::walk_path_dir(wpath.c_str(), func); } diff --git a/tdutils/td/utils/port/wstring_convert.cpp b/tdutils/td/utils/port/wstring_convert.cpp index 56da62b9..8dd83cc7 100644 --- a/tdutils/td/utils/port/wstring_convert.cpp +++ b/tdutils/td/utils/port/wstring_convert.cpp @@ -31,7 +31,7 @@ class UsableFacet : public Facet { }; } // namespace detail -Result to_wstring(Slice slice) { +Result to_wstring(CSlice slice) { // TODO(perf): optimize std::wstring_convert>> converter; auto res = converter.from_bytes(slice.begin(), slice.end()); diff --git a/tdutils/td/utils/port/wstring_convert.h b/tdutils/td/utils/port/wstring_convert.h index a795d2bd..5d6ed69d 100644 --- a/tdutils/td/utils/port/wstring_convert.h +++ b/tdutils/td/utils/port/wstring_convert.h @@ -18,7 +18,7 @@ namespace td { -Result to_wstring(Slice slice); +Result to_wstring(CSlice slice); Result from_wstring(const std::wstring &str);