| 714 | Return true if successful. */ |
| 715 | |
| 716 | static bool |
| 717 | install_file_in_file (char const *from, char const *to, |
| 718 | int to_dirfd, char const *to_relname, |
| 719 | const struct cp_options *x) |
| 720 | { |
| 721 | struct stat from_sb; |
| 722 | if (x->preserve_timestamps && stat (from, &from_sb) != 0) |
| 723 | { |
| 724 | error (0, errno, _("cannot stat %s"), quoteaf (from)); |
| 725 | return false; |
| 726 | } |
| 727 | enum copy_status copy_status = copy_file (from, to, to_dirfd, to_relname, x); |
| 728 | if (copy_status == COPY_FAILED) |
| 729 | return false; |
| 730 | if (copy_status == COPY_OK && strip_files && ! strip (to)) |
| 731 | { |
| 732 | if (unlinkat (to_dirfd, to_relname, 0) != 0) /* Cleanup. */ |
| 733 | error (EXIT_FAILURE, errno, _("cannot unlink %s"), quoteaf (to)); |
| 734 | return false; |
| 735 | } |
| 736 | if (x->preserve_timestamps && (copy_status == COPY_SKIPPED || strip_files |
| 737 | || ! S_ISREG (from_sb.st_mode)) |
| 738 | && ! change_timestamps (&from_sb, to, to_dirfd, to_relname)) |
| 739 | return false; |
| 740 | return change_attributes (to, to_dirfd, to_relname); |
| 741 | } |
| 742 | |
| 743 | /* Create any missing parent directories of TO, |
| 744 | while maintaining the current Working Directory. |
no test coverage detected