Report — never delete — the updater script sitting next to the binary. * * install.sh/install.ps1 copies itself beside the executable so `update` has * something to hand off to. Uninstall does NOT remove it, deliberately: we * cannot prove we own that file. The user may have put their own copy there, it * may be a symlink into a checkout, or a package manager may manage it. Deleting * a file
| 11263 | * shouldn't. Telling the user the exact path costs one line and leaves the |
| 11264 | * decision with them. */ |
| 11265 | static void cli_uninstall_report_leftover_installer(const char *bin_path, bool dry_run) { |
| 11266 | if (!bin_path || !bin_path[0]) { |
| 11267 | return; |
| 11268 | } |
| 11269 | const char *slash = strrchr(bin_path, '/'); |
| 11270 | #ifdef _WIN32 |
| 11271 | const char *backslash = strrchr(bin_path, '\\'); |
| 11272 | if (backslash && (!slash || backslash > slash)) { |
| 11273 | slash = backslash; |
| 11274 | } |
| 11275 | static const char *const installer_names[] = {"install.ps1", "install.sh"}; |
| 11276 | #else |
| 11277 | static const char *const installer_names[] = {"install.sh"}; |
| 11278 | #endif |
| 11279 | if (!slash || slash == bin_path) { |
| 11280 | return; |
| 11281 | } |
| 11282 | size_t dir_len = (size_t)(slash - bin_path); |
| 11283 | for (size_t i = 0; i < sizeof(installer_names) / sizeof(installer_names[0]); i++) { |
| 11284 | char installer_path[CLI_BUF_1K]; |
| 11285 | int written = snprintf(installer_path, sizeof(installer_path), "%.*s/%s", (int)dir_len, |
| 11286 | bin_path, installer_names[i]); |
| 11287 | if (written <= 0 || (size_t)written >= sizeof(installer_path)) { |
| 11288 | continue; |
| 11289 | } |
| 11290 | struct stat installer_status; |
| 11291 | if (stat(installer_path, &installer_status) != 0) { |
| 11292 | continue; |
| 11293 | } |
| 11294 | if (dry_run) { |
| 11295 | printf("Would leave %s in place (remove it yourself if you want it gone).\n", |
| 11296 | installer_path); |
| 11297 | } else { |
| 11298 | printf("\nLeft in place: %s\n" |
| 11299 | " This is the updater; uninstall does not delete it because it cannot\n" |
| 11300 | " prove it owns it. To remove it as well:\n\n rm \"%s\"\n", |
| 11301 | installer_path, installer_path); |
| 11302 | } |
| 11303 | } |
| 11304 | } |
| 11305 | |
| 11306 | /* Uninstall is an activation too: removing the executable or its indexes |
| 11307 | * while a daemon generation is starting/running would leave live sessions on |
no test coverage detected