| 797 | Return true if successful. */ |
| 798 | |
| 799 | static bool |
| 800 | install_file_in_dir (char const *from, char const *to_dir, |
| 801 | const struct cp_options *x, bool mkdir_and_install, |
| 802 | int *target_dirfd) |
| 803 | { |
| 804 | char const *from_base = last_component (from); |
| 805 | char *to_relname; |
| 806 | char *to = file_name_concat (to_dir, from_base, &to_relname); |
| 807 | bool ret = true; |
| 808 | |
| 809 | if (!target_dirfd_valid (*target_dirfd) |
| 810 | && (ret = mkdir_and_install) |
| 811 | && (ret = mkancesdirs_safe_wd (from, to, (struct cp_options *) x, true))) |
| 812 | { |
| 813 | int fd = open (to_dir, O_PATHSEARCH | O_DIRECTORY); |
| 814 | if (fd < 0) |
| 815 | { |
| 816 | error (0, errno, _("cannot open %s"), quoteaf (to)); |
| 817 | ret = false; |
| 818 | } |
| 819 | else |
| 820 | *target_dirfd = fd; |
| 821 | } |
| 822 | |
| 823 | if (ret) |
| 824 | { |
| 825 | int to_dirfd = *target_dirfd; |
| 826 | if (!target_dirfd_valid (to_dirfd)) |
| 827 | { |
| 828 | to_dirfd = AT_FDCWD; |
| 829 | to_relname = to; |
| 830 | } |
| 831 | ret = install_file_in_file (from, to, to_dirfd, to_relname, x); |
| 832 | } |
| 833 | |
| 834 | free (to); |
| 835 | return ret; |
| 836 | } |
| 837 | |
| 838 | int |
| 839 | main (int argc, char **argv) |
no test coverage detected