From 0b8c616dd0ab81bcef3c944ccb2a343acb51acdd Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Sat, 8 Aug 2026 01:27:46 +0200 Subject: [PATCH] cont --- tools/server/server-tools.cpp | 42 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/tools/server/server-tools.cpp b/tools/server/server-tools.cpp index 758714b69a..c5bad891c6 100644 --- a/tools/server/server-tools.cpp +++ b/tools/server/server-tools.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,14 @@ static int entry_depth(const std::string & rel) { return 1 + (int) std::count(rel.begin(), rel.end(), '/'); } +// directories a listing still reports but never descends into: they can be enormous. +// shared by the local walker and the `find` expression built for the container. +// lowercase only: the local walker case-folds a name before looking it up +static const char * const SERVER_TOOL_JUNK_DIR_NAMES[] = { + ".git", ".svn", ".hg", "node_modules", "__pycache__", + ".venv", "venv", "dist", "build", "target", ".cache", ".idea", ".vscode", +}; + class tools_io { public: struct exec_result { @@ -400,10 +409,8 @@ private: } static const std::unordered_set & junk_dir_names() { - static const std::unordered_set names = { - ".git", ".svn", ".hg", "node_modules", "__pycache__", - ".venv", "venv", "dist", "build", "target", ".cache", ".idea", ".vscode", - }; + static const std::unordered_set names( + std::begin(SERVER_TOOL_JUNK_DIR_NAMES), std::end(SERVER_TOOL_JUNK_DIR_NAMES)); return names; } @@ -479,6 +486,15 @@ public: tools_io_docker(std::string container_id, std::string cwd = "") : container_id(std::move(container_id)), cwd(std::move(cwd)) {} + // resolves `path` against `cwd` if `path` is relative and `cwd` is set; otherwise returns `path` unchanged. + // container paths are always POSIX-style ('/'), regardless of host OS. + std::string resolve(const std::string & path) const override { + if (cwd.empty() || (!path.empty() && path[0] == '/')) { + return path; + } + return cwd + "/" + path; + } + bool is_directory(const std::string & path) const override { return shell_test("-d", resolve(path)); } @@ -603,15 +619,6 @@ private: std::string container_id; std::string cwd; - // resolves `path` against `cwd` if `path` is relative and `cwd` is set; otherwise returns `path` unchanged. - // container paths are always POSIX-style ('/'), regardless of host OS. - std::string resolve(const std::string & path) const { - if (cwd.empty() || (!path.empty() && path[0] == '/')) { - return path; - } - return cwd + "/" + path; - } - exec_result exec(const std::vector & inner, size_t max_output, bool combine_stderr) const { std::vector args = {"docker", "exec", container_id}; args.insert(args.end(), inner.begin(), inner.end()); @@ -644,13 +651,8 @@ private: // one `find` pass in the container. junk directories stay selectable but are never descended into, // and -mindepth/-maxdepth keep a busybox image working as well as a GNU one std::vector find_entries(const std::string & abs_base, int max_depth, bool dirs, bool & truncated) const { - static const char * junk_names[] = { - ".git", ".svn", ".hg", "node_modules", "__pycache__", - ".venv", "venv", "dist", "build", "target", ".cache", ".idea", ".vscode", - }; - std::string prune_expr; - for (const char * n : junk_names) { + for (const char * n : SERVER_TOOL_JUNK_DIR_NAMES) { if (!prune_expr.empty()) prune_expr += " -o "; prune_expr += std::string("-name ") + n; } @@ -1589,6 +1591,8 @@ struct server_tool_get_info : server_tool { #endif auto res = io->run(args, SERVER_TOOL_GET_INFO_MAX_OUTPUT, SERVER_TOOL_GET_INFO_TIMEOUT); + // "ver" prints a blank line before the version, so the output is stripped on both ends; + // a failed spawn or a timeout leaves a diagnostic in res.output, which is not an OS name std::string os_info = res.exit_code == 0 && !res.timed_out ? string_strip(res.output) : "unknown"; std::string cwd = json_value(params, "cwd", std::string());