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
| 10910 | * shouldn't. Telling the user the exact path costs one line and leaves the |
| 10911 | * decision with them. */ |
| 10912 | static void cli_uninstall_report_leftover_installer(const char *bin_path, bool dry_run) { |
| 10913 | if (!bin_path || !bin_path[0]) { |
| 10914 | return; |
| 10915 | } |
| 10916 | const char *slash = strrchr(bin_path, '/'); |
| 10917 | #ifdef _WIN32 |
| 10918 | const char *backslash = strrchr(bin_path, '\\'); |
| 10919 | if (backslash && (!slash || backslash > slash)) { |
| 10920 | slash = backslash; |
| 10921 | } |
| 10922 | static const char *const installer_names[] = {"install.ps1", "install.sh"}; |
| 10923 | #else |
| 10924 | static const char *const installer_names[] = {"install.sh"}; |
| 10925 | #endif |
| 10926 | if (!slash || slash == bin_path) { |
| 10927 | return; |
| 10928 | } |
| 10929 | size_t dir_len = (size_t)(slash - bin_path); |
| 10930 | for (size_t i = 0; i < sizeof(installer_names) / sizeof(installer_names[0]); i++) { |
| 10931 | char installer_path[CLI_BUF_1K]; |
| 10932 | int written = snprintf(installer_path, sizeof(installer_path), "%.*s/%s", (int)dir_len, |
| 10933 | bin_path, installer_names[i]); |
| 10934 | if (written <= 0 || (size_t)written >= sizeof(installer_path)) { |
| 10935 | continue; |
| 10936 | } |
| 10937 | struct stat installer_status; |
| 10938 | if (stat(installer_path, &installer_status) != 0) { |
| 10939 | continue; |
| 10940 | } |
| 10941 | if (dry_run) { |
| 10942 | printf("Would leave %s in place (remove it yourself if you want it gone).\n", |
| 10943 | installer_path); |
| 10944 | } else { |
| 10945 | printf("\nLeft in place: %s\n" |
| 10946 | " This is the updater; uninstall does not delete it because it cannot\n" |
| 10947 | " prove it owns it. To remove it as well:\n\n rm \"%s\"\n", |
| 10948 | installer_path, installer_path); |
| 10949 | } |
| 10950 | } |
| 10951 | } |
| 10952 | |
| 10953 | /* Uninstall is an activation too: removing the executable or its indexes |
| 10954 | * while a daemon generation is starting/running would leave live sessions on |
no test coverage detected