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