common : add getpwuid fallback for HF cache when HOME is not set (#21035)
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
parent
a73bbd5d92
commit
287b5b1eab
1 changed files with 9 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ namespace nl = nlohmann;
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#define HOME_DIR "HOME"
|
#define HOME_DIR "HOME"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace hf_cache {
|
namespace hf_cache {
|
||||||
|
|
@ -51,6 +53,13 @@ static fs::path get_cache_directory() {
|
||||||
return entry.path.empty() ? base : base / entry.path;
|
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");
|
throw std::runtime_error("Failed to determine HF cache directory");
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue