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
| 10848 | * shouldn't. Telling the user the exact path costs one line and leaves the |
| 10849 | * decision with them. */ |
| 10850 | static void cli_uninstall_report_leftover_installer(const char *bin_path, bool dry_run) { |
| 10851 | if (!bin_path || !bin_path[0]) { |
| 10852 | return; |
| 10853 | } |
| 10854 | const char *slash = strrchr(bin_path, '/'); |
| 10855 | #ifdef _WIN32 |
| 10856 | const char *backslash = strrchr(bin_path, '\\'); |
| 10857 | if (backslash && (!slash || backslash > slash)) { |
| 10858 | slash = backslash; |
| 10859 | } |
| 10860 | static const char *const installer_names[] = {"install.ps1", "install.sh"}; |
| 10861 | #else |
| 10862 | static const char *const installer_names[] = {"install.sh"}; |
| 10863 | #endif |
| 10864 | if (!slash || slash == bin_path) { |
| 10865 | return; |
| 10866 | } |
| 10867 | size_t dir_len = (size_t)(slash - bin_path); |
| 10868 | for (size_t i = 0; i < sizeof(installer_names) / sizeof(installer_names[0]); i++) { |
| 10869 | char installer_path[CLI_BUF_1K]; |
| 10870 | int written = snprintf(installer_path, sizeof(installer_path), "%.*s/%s", (int)dir_len, |
| 10871 | bin_path, installer_names[i]); |
| 10872 | if (written <= 0 || (size_t)written >= sizeof(installer_path)) { |
| 10873 | continue; |
| 10874 | } |
| 10875 | struct stat installer_status; |
| 10876 | if (stat(installer_path, &installer_status) != 0) { |
| 10877 | continue; |
| 10878 | } |
| 10879 | if (dry_run) { |
| 10880 | printf("Would leave %s in place (remove it yourself if you want it gone).\n", |
| 10881 | installer_path); |
| 10882 | } else { |
| 10883 | printf("\nLeft in place: %s\n" |
| 10884 | " This is the updater; uninstall does not delete it because it cannot\n" |
| 10885 | " prove it owns it. To remove it as well:\n\n rm \"%s\"\n", |
| 10886 | installer_path, installer_path); |
| 10887 | } |
| 10888 | } |
| 10889 | } |
| 10890 | |
| 10891 | /* Uninstall is an activation too: removing the executable or its indexes |
| 10892 | * while a daemon generation is starting/running would leave live sessions on |
no test coverage detected