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>
This commit is contained in:
Adrien Gallouët
2026-10-01 20:15:02 +02:00
committed by GitHub
parent 68e79bd8cd
commit f1cee9941b
3 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -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));
}
+9
View File
@@ -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();
+10 -1
View File
@@ -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;