diff --git a/gtk/FreeSpaceLabel.cc b/gtk/FreeSpaceLabel.cc index 1b8c82959..83db14085 100644 --- a/gtk/FreeSpaceLabel.cc +++ b/gtk/FreeSpaceLabel.cc @@ -54,7 +54,7 @@ bool FreeSpaceLabel::Impl::on_freespace_timer() } auto ec = std::error_code{}; - auto const capacity = std::filesystem::space(dir_, ec); + auto const capacity = std::filesystem::space(tr_u8path(dir_), ec); auto const text = !ec ? fmt::format(fmt::runtime(_("{disk_space} free")), fmt::arg("disk_space", tr_strlsize(capacity.available))) : _("Error"); diff --git a/libtransmission/file.h b/libtransmission/file.h index 7dfd06098..bf18be751 100644 --- a/libtransmission/file.h +++ b/libtransmission/file.h @@ -7,8 +7,10 @@ #include // uint64_t #include // time_t +#include #include #include +#include #include #include #include @@ -508,3 +510,25 @@ bool tr_sys_dir_close(tr_sys_dir_t handle, tr_error* error = nullptr); /** @} */ /** @} */ + +/** + * Temporary replacement of deprecated `std::filesystem::u8path()` while we migrate + * from char to char8_t strings. + * + * https://stackoverflow.com/a/57635139/11390656 + * @{ + */ + +template +[[nodiscard]] std::filesystem::path tr_u8path(InputIt begin, InputIt end) +{ + auto const view = std::ranges::subrange(begin, end) | std::views::transform([](char const c) -> char8_t { return c; }); + return { view.begin(), view.end() }; +} + +[[nodiscard]] inline std::filesystem::path tr_u8path(std::string_view path) +{ + return tr_u8path(path.begin(), path.end()); +} + +/// @} diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 98847f293..9b3993f8e 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -2232,7 +2232,7 @@ using SessionAccessors = std::pair; [](tr_session const& src) -> tr_variant { auto ec = std::error_code{}; - auto const space = std::filesystem::space(src.downloadDir(), ec); + auto const space = std::filesystem::space(tr_u8path(src.downloadDir()), ec); return !ec ? space.available : tr_variant{ -1 }; }, nullptr); @@ -2737,7 +2737,7 @@ using SessionAccessors = std::pair; // get the free space auto ec = std::error_code{}; - auto const capacity = std::filesystem::space(*path, ec); + auto const capacity = std::filesystem::space(tr_u8path(*path), ec); // response args_out.try_emplace(TR_KEY_path, *path);