| 745 | Return true if successful. */ |
| 746 | |
| 747 | static bool |
| 748 | mkancesdirs_safe_wd (char const *from, char *to, struct cp_options *x, |
| 749 | bool save_always) |
| 750 | { |
| 751 | bool save_working_directory = |
| 752 | save_always |
| 753 | || ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to)); |
| 754 | |
| 755 | struct savewd wd; |
| 756 | savewd_init (&wd); |
| 757 | if (! save_working_directory) |
| 758 | savewd_finish (&wd); |
| 759 | |
| 760 | int status = EXIT_SUCCESS; |
| 761 | if (mkancesdirs (to, &wd, make_ancestor, x) == -1) |
| 762 | { |
| 763 | error (0, errno, _("cannot create directory %s"), quoteaf (to)); |
| 764 | status = EXIT_FAILURE; |
| 765 | } |
| 766 | |
| 767 | if (save_working_directory) |
| 768 | { |
| 769 | int restore_result = savewd_restore (&wd, status); |
| 770 | int restore_errno = errno; |
| 771 | savewd_finish (&wd); |
| 772 | if (EXIT_SUCCESS < restore_result) |
| 773 | return false; |
| 774 | if (restore_result < 0 && status == EXIT_SUCCESS) |
| 775 | { |
| 776 | error (0, restore_errno, _("cannot create directory %s"), |
| 777 | quoteaf (to)); |
| 778 | return false; |
| 779 | } |
| 780 | } |
| 781 | return status == EXIT_SUCCESS; |
| 782 | } |
| 783 | |
| 784 | /* Copy file FROM onto file TO, creating any missing parent directories of TO. |
| 785 | Return true if successful. */ |
no outgoing calls
no test coverage detected