Commit f1cee9941 for llama.cpp
commit f1cee9941b0e843ea260bf8dd9a090fbd9711b6a
Author: Adrien Gallouët <angt@huggingface.co>
Date: Thu Oct 1 20:15:02 2026 +0200
common,rpc : fix cache dir creation through symlinks on buggy libstdc++ (#29816)
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510
Close #29759
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
diff --git a/common/common.cpp b/common/common.cpp
index 401de1dc2..7ebfa2610 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -1023,7 +1023,7 @@ std::filesystem::path fs_get_cache_file(const std::string & filename) {
GGML_ASSERT(filename.find(DIRECTORY_SEPARATOR) == std::string::npos);
const std::filesystem::path cache_directory = fs_get_cache_directory();
std::error_code ec;
- std::filesystem::create_directories(cache_directory, ec);
+ common_create_directories(cache_directory, ec);
if (ec) {
throw std::runtime_error("failed to create cache directory: " + fs_path_to_utf8(cache_directory));
}
diff --git a/common/common.h b/common/common.h
index dcc5ec1ae..fd90c3b95 100644
--- a/common/common.h
+++ b/common/common.h
@@ -914,6 +914,15 @@ std::filesystem::path common_get_path_from_env(const std::string & name);
bool fs_validate_filename(const std::string & filename, bool allow_subdirs = false);
bool fs_is_directory(const std::string & path);
+// some old libstdc++ versions don't follow symlinks here, so adding a trailing "/" fixes it: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510
+inline bool common_create_directories(const std::filesystem::path & path, std::error_code & ec) {
+#if defined(__linux__)
+ return std::filesystem::create_directories(path / "", ec);
+#else
+ return std::filesystem::create_directories(path, ec);
+#endif
+}
+
std::filesystem::path fs_get_cache_directory();
std::filesystem::path fs_get_cache_file(const std::string & filename);
std::filesystem::path fs_get_config_directory();
diff --git a/tools/rpc/rpc-server.cpp b/tools/rpc/rpc-server.cpp
index c0c55df59..2ae11cb3b 100644
--- a/tools/rpc/rpc-server.cpp
+++ b/tools/rpc/rpc-server.cpp
@@ -82,6 +82,15 @@ static std::filesystem::path fs_get_cache_directory() {
return cache_directory / "llama.cpp";
}
+// NOTE: this is copied from common.h to avoid linking with libcommon
+static bool common_create_directories(const std::filesystem::path & path, std::error_code & ec) {
+#if defined(__linux__)
+ return std::filesystem::create_directories(path / "", ec);
+#else
+ return std::filesystem::create_directories(path, ec);
+#endif
+}
+
struct rpc_server_params {
std::string host = "127.0.0.1";
int port = 50052;
@@ -233,7 +242,7 @@ int main(int argc, char * argv[]) {
if (params.use_cache) {
const std::filesystem::path cache_dir_path = fs_get_cache_directory() / "rpc";
std::error_code ec;
- std::filesystem::create_directories(cache_dir_path, ec);
+ common_create_directories(cache_dir_path, ec);
if (ec) {
fprintf(stderr, "Failed to create cache directory: %s\n", fs_path_to_utf8(cache_dir_path).c_str());
return 1;