fix missing slash in fs_get_cache_directory()

This commit is contained in:
ngxson 2024-05-24 00:23:23 +02:00
parent 74f33adf5f
commit c11fa8c8ed

View file

@ -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 = "";
if (getenv("LLAMA_CACHE")) { auto ensure_trailing_slash = [](std::string p) {
cache_directory = std::getenv("LLAMA_CACHE"); // Make sure to add trailing slash
if (cache_directory.back() != DIRECTORY_SEPARATOR) { if (p.back() != DIRECTORY_SEPARATOR) {
cache_directory += DIRECTORY_SEPARATOR; p += DIRECTORY_SEPARATOR;
} }
return p;
};
if (getenv("LLAMA_CACHE")) {
cache_directory = ensure_trailing_slash(std::getenv("LLAMA_CACHE"));
} else { } else {
#ifdef __linux__ #ifdef __linux__
if (std::getenv("XDG_CACHE_HOME")) { if (std::getenv("XDG_CACHE_HOME")) {
@ -1872,6 +1876,7 @@ std::string fs_get_cache_directory() {
#elif defined(_WIN32) #elif defined(_WIN32)
cache_directory = std::getenv("APPDATA"); cache_directory = std::getenv("APPDATA");
#endif // __linux__ #endif // __linux__
cache_directory = ensure_trailing_slash(cache_directory);
cache_directory += "llama.cpp"; cache_directory += "llama.cpp";
cache_directory += DIRECTORY_SEPARATOR; cache_directory += DIRECTORY_SEPARATOR;
} }