mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-12 03:31:46 +00:00
fix missing slash in fs_get_cache_directory()
(#7503)
* fix missing slash in fs_get_cache_directory() * use LOCALAPPDATA for fs_get_cache_directory() * better code style
This commit is contained in:
parent
57684331fc
commit
902184dd3a
@ -1855,11 +1855,15 @@ bool fs_create_directory_with_parents(const std::string & path) {
|
|||||||
|
|
||||||
std::string fs_get_cache_directory() {
|
std::string fs_get_cache_directory() {
|
||||||
std::string cache_directory = "";
|
std::string cache_directory = "";
|
||||||
|
auto ensure_trailing_slash = [](std::string p) {
|
||||||
|
// Make sure to add trailing slash
|
||||||
|
if (p.back() != DIRECTORY_SEPARATOR) {
|
||||||
|
p += DIRECTORY_SEPARATOR;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
};
|
||||||
if (getenv("LLAMA_CACHE")) {
|
if (getenv("LLAMA_CACHE")) {
|
||||||
cache_directory = std::getenv("LLAMA_CACHE");
|
cache_directory = std::getenv("LLAMA_CACHE");
|
||||||
if (cache_directory.back() != DIRECTORY_SEPARATOR) {
|
|
||||||
cache_directory += DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (std::getenv("XDG_CACHE_HOME")) {
|
if (std::getenv("XDG_CACHE_HOME")) {
|
||||||
@ -1870,12 +1874,12 @@ std::string fs_get_cache_directory() {
|
|||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
|
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
cache_directory = std::getenv("APPDATA");
|
cache_directory = std::getenv("LOCALAPPDATA");
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
cache_directory = ensure_trailing_slash(cache_directory);
|
||||||
cache_directory += "llama.cpp";
|
cache_directory += "llama.cpp";
|
||||||
cache_directory += DIRECTORY_SEPARATOR;
|
|
||||||
}
|
}
|
||||||
return cache_directory;
|
return ensure_trailing_slash(cache_directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user