diff --git a/common/hf-cache.cpp b/common/hf-cache.cpp index 80dcab0177..665c9ff066 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"); }();