| 648 | } |
| 649 | |
| 650 | bool cmFileCopier::InstallDirectory(std::string const& source, |
| 651 | std::string const& destination, |
| 652 | MatchProperties match_properties) |
| 653 | { |
| 654 | // Inform the user about this directory installation. |
| 655 | this->ReportCopy(destination, TypeDir, |
| 656 | !( // Report "Up-to-date:" for existing directories, |
| 657 | // but not symlinks to them. |
| 658 | cmSystemTools::FileIsDirectory(destination) && |
| 659 | !cmSystemTools::FileIsSymlink(destination))); |
| 660 | |
| 661 | // check if default dir creation permissions were set |
| 662 | mode_t default_dir_mode_v = 0; |
| 663 | mode_t* default_dir_mode = &default_dir_mode_v; |
| 664 | if (!this->GetDefaultDirectoryPermissions(&default_dir_mode)) { |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | // Make sure the destination directory exists. |
| 669 | auto makedir_status = |
| 670 | cmSystemTools::MakeDirectory(destination, default_dir_mode); |
| 671 | if (!makedir_status) { |
| 672 | std::ostringstream e; |
| 673 | e << this->Name << " cannot make directory \"" << destination |
| 674 | << "\": " << makedir_status.GetString() << "."; |
| 675 | this->Status.SetError(e.str()); |
| 676 | return false; |
| 677 | } |
| 678 | |
| 679 | // Compute the requested permissions for the destination directory. |
| 680 | mode_t permissions = |
| 681 | (match_properties.Permissions ? match_properties.Permissions |
| 682 | : this->DirPermissions); |
| 683 | if (!permissions) { |
| 684 | // No permissions were explicitly provided but the user requested |
| 685 | // that the source directory permissions be used. |
| 686 | cmSystemTools::GetPermissions(source, permissions); |
| 687 | } |
| 688 | |
| 689 | // Compute the set of permissions required on this directory to |
| 690 | // recursively install files and subdirectories safely. |
| 691 | mode_t required_permissions = |
| 692 | mode_owner_read | mode_owner_write | mode_owner_execute; |
| 693 | |
| 694 | // If the required permissions are specified it is safe to set the |
| 695 | // final permissions now. Otherwise we must add the required |
| 696 | // permissions temporarily during file installation. |
| 697 | mode_t permissions_before = 0; |
| 698 | mode_t permissions_after = 0; |
| 699 | if ((permissions & required_permissions) == required_permissions) { |
| 700 | permissions_before = permissions; |
| 701 | } else { |
| 702 | permissions_before = permissions | required_permissions; |
| 703 | permissions_after = permissions; |
| 704 | } |
| 705 | |
| 706 | // Set the required permissions of the destination directory. |
| 707 | if (!this->SetPermissions(destination, permissions_before)) { |
no test coverage detected