From f1cee9941b0e843ea260bf8dd9a090fbd9711b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 1 Oct 2026 20:15:02 +0200 Subject: [PATCH] common,rpc : fix cache dir creation through symlinks on buggy libstdc++ (#29816) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510 Close #29759 Signed-off-by: Adrien Gallouët --- common/common.cpp | 2 +- common/common.h | 9 +++++++++ tools/rpc/rpc-server.cpp | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 401de1dc2a..7ebfa26103 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 dcc5ec1aef..fd90c3b95b 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 c0c55df59d..2ae11cb3b5 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;