LLM inference in C/C++
C++ ggml
common,rpc : fix cache dir creation through symlinks on buggy libstdc++ (#29816)
Adrien Gallouëtf1cee9941b0e
diff --git a/common/common.cpp b/common/common.cppindex 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.hindex 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.cppindex 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;