Skip to content

Commit

Permalink
fix missing slash in fs_get_cache_directory() (ggerganov#7503)
Browse files Browse the repository at this point in the history
* fix missing slash in fs_get_cache_directory()

* use LOCALAPPDATA for fs_get_cache_directory()

* better code style
  • Loading branch information
ngxson authored May 25, 2024
1 parent 5768433 commit 902184d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,11 +1855,15 @@ bool fs_create_directory_with_parents(const std::string & path) {

std::string fs_get_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")) {
cache_directory = std::getenv("LLAMA_CACHE");
if (cache_directory.back() != DIRECTORY_SEPARATOR) {
cache_directory += DIRECTORY_SEPARATOR;
}
} else {
#ifdef __linux__
if (std::getenv("XDG_CACHE_HOME")) {
Expand All @@ -1870,12 +1874,12 @@ std::string fs_get_cache_directory() {
#elif defined(__APPLE__)
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
#elif defined(_WIN32)
cache_directory = std::getenv("APPDATA");
cache_directory = std::getenv("LOCALAPPDATA");
#endif // __linux__
cache_directory = ensure_trailing_slash(cache_directory);
cache_directory += "llama.cpp";
cache_directory += DIRECTORY_SEPARATOR;
}
return cache_directory;
return ensure_trailing_slash(cache_directory);
}


Expand Down

0 comments on commit 902184d

Please sign in to comment.