From: Adrien Gallouët Date: Thu, 26 Mar 2026 19:34:23 +0000 (+0100) Subject: common : add getpwuid fallback for HF cache when HOME is not set (#21035) X-Git-Tag: upstream/0.0.8611~68 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=287b5b1eab2b059357b6cf6615c8172334e1ed42;p=pkg%2Fggml%2Fsources%2Fllama.cpp common : add getpwuid fallback for HF cache when HOME is not set (#21035) Signed-off-by: Adrien Gallouët --- diff --git a/common/hf-cache.cpp b/common/hf-cache.cpp index 80dcab017..665c9ff06 100644 --- a/common/hf-cache.cpp +++ b/common/hf-cache.cpp @@ -26,6 +26,8 @@ namespace nl = nlohmann; #include #else #define HOME_DIR "HOME" +#include +#include #endif namespace hf_cache { @@ -51,6 +53,13 @@ static fs::path get_cache_directory() { return entry.path.empty() ? base : base / entry.path; } } +#ifndef _WIN32 + const struct passwd * pw = getpwuid(getuid()); + + if (pw->pw_dir && *pw->pw_dir) { + return fs::path(pw->pw_dir) / ".cache" / "huggingface" / "hub"; + } +#endif throw std::runtime_error("Failed to determine HF cache directory"); }();