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
| 11497 | * shouldn't. Telling the user the exact path costs one line and leaves the |
| 11498 | * decision with them. */ |
| 11499 | static void cli_uninstall_report_leftover_installer(const char *bin_path, bool dry_run) { |
| 11500 | if (!bin_path || !bin_path[0]) { |
| 11501 | return; |
| 11502 | } |
| 11503 | const char *slash = strrchr(bin_path, '/'); |
| 11504 | #ifdef _WIN32 |
| 11505 | const char *backslash = strrchr(bin_path, '\\'); |
| 11506 | if (backslash && (!slash || backslash > slash)) { |
| 11507 | slash = backslash; |
| 11508 | } |
| 11509 | static const char *const installer_names[] = {"install.ps1", "install.sh"}; |
| 11510 | #else |
| 11511 | static const char *const installer_names[] = {"install.sh"}; |
| 11512 | #endif |
| 11513 | if (!slash || slash == bin_path) { |
| 11514 | return; |
| 11515 | } |
| 11516 | size_t dir_len = (size_t)(slash - bin_path); |
| 11517 | for (size_t i = 0; i < sizeof(installer_names) / sizeof(installer_names[0]); i++) { |
| 11518 | char installer_path[CLI_BUF_1K]; |
| 11519 | int written = snprintf(installer_path, sizeof(installer_path), "%.*s/%s", (int)dir_len, |
| 11520 | bin_path, installer_names[i]); |
| 11521 | if (written <= 0 || (size_t)written >= sizeof(installer_path)) { |
| 11522 | continue; |
| 11523 | } |
| 11524 | struct stat installer_status; |
| 11525 | if (stat(installer_path, &installer_status) != 0) { |
| 11526 | continue; |
| 11527 | } |
| 11528 | if (dry_run) { |
| 11529 | printf("Would leave %s in place (remove it yourself if you want it gone).\n", |
| 11530 | installer_path); |
| 11531 | } else { |
| 11532 | printf("\nLeft in place: %s\n" |
| 11533 | " This is the updater; uninstall does not delete it because it cannot\n" |
| 11534 | " prove it owns it. To remove it as well:\n\n rm \"%s\"\n", |
| 11535 | installer_path, installer_path); |
| 11536 | } |
| 11537 | } |
| 11538 | } |
| 11539 | |
| 11540 | /* Uninstall is an activation too: removing the executable or its indexes |
| 11541 | * while a daemon generation is starting/running would leave live sessions on |
no test coverage detected