]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
common : add getpwuid fallback for HF cache when HOME is not set (#21035)
authorAdrien Gallouët <redacted>
Thu, 26 Mar 2026 19:34:23 +0000 (20:34 +0100)
committerGitHub <redacted>
Thu, 26 Mar 2026 19:34:23 +0000 (20:34 +0100)
Signed-off-by: Adrien Gallouët <redacted>
common/hf-cache.cpp

index 80dcab0177af5a6c7eefd3caa7f681dab533bbab..665c9ff066a5ba174a2651c313916a84006cb4ac 100644 (file)
@@ -26,6 +26,8 @@ namespace nl = nlohmann;
 #include <windows.h>
 #else
 #define HOME_DIR "HOME"
+#include <unistd.h>
+#include <pwd.h>
 #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");
     }();