Skip to content

Commit 902184d

Browse files
authored
fix missing slash in fs_get_cache_directory() (ggml-org#7503)
* fix missing slash in fs_get_cache_directory() * use LOCALAPPDATA for fs_get_cache_directory() * better code style
1 parent 5768433 commit 902184d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

common/common.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,11 +1855,15 @@ bool fs_create_directory_with_parents(const std::string & path) {
18551855

18561856
std::string fs_get_cache_directory() {
18571857
std::string cache_directory = "";
1858+
auto ensure_trailing_slash = [](std::string p) {
1859+
// Make sure to add trailing slash
1860+
if (p.back() != DIRECTORY_SEPARATOR) {
1861+
p += DIRECTORY_SEPARATOR;
1862+
}
1863+
return p;
1864+
};
18581865
if (getenv("LLAMA_CACHE")) {
18591866
cache_directory = std::getenv("LLAMA_CACHE");
1860-
if (cache_directory.back() != DIRECTORY_SEPARATOR) {
1861-
cache_directory += DIRECTORY_SEPARATOR;
1862-
}
18631867
} else {
18641868
#ifdef __linux__
18651869
if (std::getenv("XDG_CACHE_HOME")) {
@@ -1870,12 +1874,12 @@ std::string fs_get_cache_directory() {
18701874
#elif defined(__APPLE__)
18711875
cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");
18721876
#elif defined(_WIN32)
1873-
cache_directory = std::getenv("APPDATA");
1877+
cache_directory = std::getenv("LOCALAPPDATA");
18741878
#endif // __linux__
1879+
cache_directory = ensure_trailing_slash(cache_directory);
18751880
cache_directory += "llama.cpp";
1876-
cache_directory += DIRECTORY_SEPARATOR;
18771881
}
1878-
return cache_directory;
1882+
return ensure_trailing_slash(cache_directory);
18791883
}
18801884

18811885

0 commit comments

Comments
 (0)