From 2ada83079afc79295b3c07bae8a74457c61cba92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 5 Nov 2026 08:37:59 +0100 Subject: [PATCH] common : drop u8path() and use generic_string() (#31681) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- common/common.cpp | 2 +- common/download.cpp | 9 ++++----- common/hf-cache.cpp | 11 +++++------ common/preset.cpp | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 20285b6f7..bc51de053 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1042,7 +1042,7 @@ std::filesystem::path fs_get_cache_file(const std::string & filename) { if (ec) { throw std::runtime_error("failed to create cache directory: " + cache_directory.string()); } - return cache_directory / std::filesystem::u8path(filename); + return cache_directory / filename; } // diff --git a/common/download.cpp b/common/download.cpp index 979dd6326..fbd192721 100644 --- a/common/download.cpp +++ b/common/download.cpp @@ -45,7 +45,7 @@ static const std::string PARTIAL_SUFFIX = ".downloadInProgress"; static void write_etag(const std::string & path, const std::string & etag) { const std::string etag_path = path + ".etag"; - fs_write_atomic(std::filesystem::u8path(etag_path), etag); + fs_write_atomic(etag_path, etag); LOG_DBG("%s: file etag saved: %s\n", __func__, etag_path.c_str()); } @@ -293,8 +293,7 @@ static int common_download_file_single_online(const std::string & url, // alt_path is the HF snapshot: the blob may have been moved there when symlinks are unavailable auto cache_hit = [&] { - return std::filesystem::exists(std::filesystem::u8path(path)) || - (!alt_path.empty() && std::filesystem::exists(std::filesystem::u8path(alt_path))); + return std::filesystem::exists(path) || (!alt_path.empty() && std::filesystem::exists(alt_path)); }; if (skip_etag && cache_hit()) { @@ -511,7 +510,7 @@ int common_download_file_single(const std::string & url, return common_download_file_single_online(url, path, online_opts, skip_etag, lock_path, alt_path); } - if (!std::filesystem::exists(std::filesystem::u8path(path))) { + if (!std::filesystem::exists(path)) { LOG_ERR("%s: required file is not available in cache (offline mode): %s\n", __func__, path.c_str()); return -1; } @@ -1212,7 +1211,7 @@ bool common_download_remove_sidecars(const std::string & hf_repo_with_tag, const for (const auto & s : sidecars) { const auto & f = plan.*s.file; if (!f.local_path.empty()) { - to_remove.emplace_back(std::filesystem::u8path(f.local_path)); + to_remove.emplace_back(f.local_path); } } if (to_remove.empty()) { diff --git a/common/hf-cache.cpp b/common/hf-cache.cpp index a7f328fea..4c65eff92 100644 --- a/common/hf-cache.cpp +++ b/common/hf-cache.cpp @@ -242,7 +242,7 @@ static std::string get_repo_commit(const std::string & repo_id, LOG_WRN("%s: skip invalid commit: %s\n", __func__, _commit.c_str()); continue; } - const fs::path candidate = fs::u8path(_name); + const fs::path candidate = _name; if (!is_valid_subpath(refs_path, candidate)) { LOG_WRN("%s: skip invalid branch: %s\n", __func__, _name.c_str()); @@ -317,7 +317,7 @@ hf_files get_repo_files(const std::string & repo_id, file.repo_id = repo_id; file.path = item["path"].get(); - const fs::path subpath = fs::u8path(file.path); + const fs::path subpath = file.path; if (!is_valid_subpath(commit_path, subpath)) { LOG_WRN("%s: skip invalid path: %s\n", __func__, file.path.c_str()); @@ -434,8 +434,7 @@ hf_files get_cached_files(const std::string & repo_id) { if (!path.empty()) { hf_file file; file.repo_id = _repo_id; - const auto generic_path = path.generic_u8string(); - file.path = std::string(generic_path.begin(), generic_path.end()); + file.path = path.generic_string(); file.local_path = entry.path().string(); file.final_path = file.local_path; files.push_back(std::move(file)); @@ -450,8 +449,8 @@ std::string finalize_file(const hf_file & file, const std::function & ke static std::atomic symlinks_disabled{false}; std::error_code ec; - fs::path local_path = fs::u8path(file.local_path); - fs::path final_path = fs::u8path(file.final_path); + fs::path local_path = file.local_path; + fs::path final_path = file.final_path; if (local_path == final_path || fs::exists(final_path, ec)) { return file.final_path; diff --git a/common/preset.cpp b/common/preset.cpp index 31a8bd513..3d90c242a 100644 --- a/common/preset.cpp +++ b/common/preset.cpp @@ -385,7 +385,7 @@ static bool is_draft_file(const std::string & fname) { } common_presets common_preset_context::load_from_models_dir(const std::string & models_dir) const { - const std::filesystem::path dir = std::filesystem::u8path(models_dir); + const std::filesystem::path dir = models_dir; if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) { throw std::runtime_error(string_format("error: '%s' does not exist or is not a directory\n", models_dir.c_str())); }