From 39eeb2d391199e7e472c32f37de2d7ac687a76db Mon Sep 17 00:00:00 2001 From: speak-agent <248744407+speak-agent@users.noreply.github.com> Date: Sat, 5 Sep 2026 05:35:10 +0800 Subject: [PATCH] fix(doctor): give the nvcc probe a directory this process created The probe wrote into a fixed `mcpp-nvcc-dryrun` under the shared temporary directory, and removed whatever was already there so the name could be reused. On a machine with more than one user that name is a path someone else can create first, and the removal is what makes that worth caring about. It now takes a random suffix, which is the pattern the p1689 scanner already uses, and it checks create_directory's return value rather than the error code: an existing directory is reported by returning false without setting an error, and entering a directory this process did not create is the case being avoided. Both controls re-run: with a working nvcc the warning does not appear; with nvcc copied to a directory holding no profile it appears and names `cicc`. --- src/doctor.cppm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/doctor.cppm b/src/doctor.cppm index ae1452ec1..27fbe5ace 100644 --- a/src/doctor.cppm +++ b/src/doctor.cppm @@ -113,12 +113,17 @@ std::optional unreachable_device_stage() { namespace fs = std::filesystem; std::error_code ec; - const auto probe = fs::temp_directory_path(ec) / "mcpp-nvcc-dryrun"; - if (ec) return std::nullopt; - fs::remove_all(probe, ec); - ec.clear(); - fs::create_directories(probe, ec); + // A fresh directory per run, on the pattern the p1689 scanner already + // uses. A fixed name under the shared temporary directory would be a + // path another user can create first, and the `remove_all` that a fixed + // name needs in order to be reusable is the part that makes that matter. + const auto probe = fs::temp_directory_path(ec) + / std::format("mcpp_nvcc_dryrun_{}", std::random_device{}()); if (ec) return std::nullopt; + // The return value, not `ec`: create_directory reports an existing + // directory by returning false without setting an error, and proceeding + // into a directory this process did not create is the case being avoided. + if (!fs::create_directory(probe, ec) || ec) return std::nullopt; struct Cleanup { fs::path dir; ~Cleanup() { std::error_code e; fs::remove_all(dir, e); }