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
| 10804 | * shouldn't. Telling the user the exact path costs one line and leaves the |
| 10805 | * decision with them. */ |
| 10806 | static void cli_uninstall_report_leftover_installer(const char *bin_path, bool dry_run) { |
| 10807 | if (!bin_path || !bin_path[0]) { |
| 10808 | return; |
| 10809 | } |
| 10810 | const char *slash = strrchr(bin_path, '/'); |
| 10811 | #ifdef _WIN32 |
| 10812 | const char *backslash = strrchr(bin_path, '\\'); |
| 10813 | if (backslash && (!slash || backslash > slash)) { |
| 10814 | slash = backslash; |
| 10815 | } |
| 10816 | static const char *const installer_names[] = {"install.ps1", "install.sh"}; |
| 10817 | #else |
| 10818 | static const char *const installer_names[] = {"install.sh"}; |
| 10819 | #endif |
| 10820 | if (!slash || slash == bin_path) { |
| 10821 | return; |
| 10822 | } |
| 10823 | size_t dir_len = (size_t)(slash - bin_path); |
| 10824 | for (size_t i = 0; i < sizeof(installer_names) / sizeof(installer_names[0]); i++) { |
| 10825 | char installer_path[CLI_BUF_1K]; |
| 10826 | int written = snprintf(installer_path, sizeof(installer_path), "%.*s/%s", (int)dir_len, |
| 10827 | bin_path, installer_names[i]); |
| 10828 | if (written <= 0 || (size_t)written >= sizeof(installer_path)) { |
| 10829 | continue; |
| 10830 | } |
| 10831 | struct stat installer_status; |
| 10832 | if (stat(installer_path, &installer_status) != 0) { |
| 10833 | continue; |
| 10834 | } |
| 10835 | if (dry_run) { |
| 10836 | printf("Would leave %s in place (remove it yourself if you want it gone).\n", |
| 10837 | installer_path); |
| 10838 | } else { |
| 10839 | printf("\nLeft in place: %s\n" |
| 10840 | " This is the updater; uninstall does not delete it because it cannot\n" |
| 10841 | " prove it owns it. To remove it as well:\n\n rm \"%s\"\n", |
| 10842 | installer_path, installer_path); |
| 10843 | } |
| 10844 | } |
| 10845 | } |
| 10846 | |
| 10847 | /* Uninstall is an activation too: removing the executable or its indexes |
| 10848 | * while a daemon generation is starting/running would leave live sessions on |
no test coverage detected