Copy the running binary into the canonical install target, preserving the * executable bit. When src and dst are the same on-disk file the copy is * skipped: cbm_copy_file opens dst "wb" before reading src, so copying a file * onto itself would truncate it to zero. Returns 0 on success or skip, * CLI_ERR on failure. Exposed (non-static) as the regression surface for the * `install --force` bi
| 382 | * CLI_ERR on failure. Exposed (non-static) as the regression surface for the |
| 383 | * `install --force` binary-swap bug (#472). */ |
| 384 | int cbm_copy_binary_to_target(const char *src, const char *dst) { |
| 385 | if (cbm_same_file(src, dst)) { |
| 386 | return 0; /* already in place — nothing to copy */ |
| 387 | } |
| 388 | if (cbm_copy_file(src, dst) != 0) { |
| 389 | return CLI_ERR; |
| 390 | } |
| 391 | #ifndef _WIN32 |
| 392 | (void)chmod(dst, CLI_OCTAL_PERM); |
| 393 | #endif |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | /* Replace a binary file. Unlinks the old file first (handles read-only and |
| 398 | * running binaries on Unix where unlink succeeds on open files). On all |
no test coverage detected