| 590 | } |
| 591 | |
| 592 | bool cmFileCopier::InstallFile(std::string const& fromFile, |
| 593 | std::string const& toFile, |
| 594 | MatchProperties match_properties) |
| 595 | { |
| 596 | // Determine whether we will copy the file. |
| 597 | bool copy = true; |
| 598 | if (!this->Always) { |
| 599 | // If both files exist with the same time do not copy. |
| 600 | if (!this->FileTimes.DifferS(fromFile, toFile)) { |
| 601 | copy = false; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // Inform the user about this file installation. |
| 606 | this->ReportCopy(toFile, TypeFile, copy); |
| 607 | |
| 608 | // Copy the file. |
| 609 | if (copy) { |
| 610 | auto copy_status = cmSystemTools::CopyAFile(fromFile, toFile); |
| 611 | if (!copy_status) { |
| 612 | std::ostringstream e; |
| 613 | e << this->Name << " cannot copy file \"" << fromFile << "\" to \"" |
| 614 | << toFile << "\": " << copy_status.GetString() << "."; |
| 615 | this->Status.SetError(e.str()); |
| 616 | return false; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // Set the file modification time of the destination file. |
| 621 | if (copy && !this->Always) { |
| 622 | // Add write permission so we can set the file time. |
| 623 | // Permissions are set unconditionally below anyway. |
| 624 | mode_t perm = 0; |
| 625 | if (cmSystemTools::GetPermissions(toFile, perm)) { |
| 626 | cmSystemTools::SetPermissions(toFile, perm | mode_owner_write); |
| 627 | } |
| 628 | auto copy_status = cmFileTimes::Copy(fromFile, toFile); |
| 629 | if (!copy_status) { |
| 630 | std::ostringstream e; |
| 631 | e << this->Name << " cannot set modification time on \"" << toFile |
| 632 | << "\": " << copy_status.GetString() << "."; |
| 633 | this->Status.SetError(e.str()); |
| 634 | return false; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | // Set permissions of the destination file. |
| 639 | mode_t permissions = |
| 640 | (match_properties.Permissions ? match_properties.Permissions |
| 641 | : this->FilePermissions); |
| 642 | if (!permissions) { |
| 643 | // No permissions were explicitly provided but the user requested |
| 644 | // that the source file permissions be used. |
| 645 | cmSystemTools::GetPermissions(fromFile, permissions); |
| 646 | } |
| 647 | return this->SetPermissions(toFile, permissions); |
| 648 | } |
| 649 |
no test coverage detected