| 439 | } |
| 440 | |
| 441 | bool cmArchiveWrite::AddFile(char const* file, size_t skip, char const* prefix) |
| 442 | { |
| 443 | this->Error = ""; |
| 444 | // Skip the file if we have no name for it. This may happen on a |
| 445 | // top-level directory, which does not need to be included anyway. |
| 446 | if (skip >= strlen(file)) { |
| 447 | return true; |
| 448 | } |
| 449 | char const* out = file + skip; |
| 450 | |
| 451 | // Meta-data. |
| 452 | std::string dest = cmStrCat(prefix ? prefix : "", out); |
| 453 | if (this->Verbose) { |
| 454 | std::cout << dest << "\n"; |
| 455 | } |
| 456 | Entry e; |
| 457 | cm_archive_entry_copy_sourcepath(e, file); |
| 458 | cm_archive_entry_copy_pathname(e, dest.c_str()); |
| 459 | if (archive_read_disk_entry_from_file(this->Disk, e, -1, nullptr) != |
| 460 | ARCHIVE_OK) { |
| 461 | this->Error = |
| 462 | cmStrCat("Unable to read from file:\n ", file, "\nbecause:\n ", |
| 463 | cm_archive_error_string(this->Disk)); |
| 464 | return false; |
| 465 | } |
| 466 | if (!this->MTime.empty()) { |
| 467 | time_t now; |
| 468 | time(&now); |
| 469 | time_t t = cm_parse_date(now, this->MTime.c_str()); |
| 470 | if (t == -1) { |
| 471 | this->Error = cmStrCat("unable to parse mtime '", this->MTime, '\''); |
| 472 | return false; |
| 473 | } |
| 474 | archive_entry_set_mtime(e, t, 0); |
| 475 | } else { |
| 476 | std::string source_date_epoch; |
| 477 | cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch); |
| 478 | if (!source_date_epoch.empty()) { |
| 479 | std::istringstream iss(source_date_epoch); |
| 480 | time_t epochTime; |
| 481 | iss >> epochTime; |
| 482 | if (iss.eof() && !iss.fail()) { |
| 483 | // Set all of the file times to the epoch time to handle archive |
| 484 | // formats that include creation/access time. |
| 485 | archive_entry_set_mtime(e, epochTime, 0); |
| 486 | archive_entry_set_atime(e, epochTime, 0); |
| 487 | archive_entry_set_ctime(e, epochTime, 0); |
| 488 | archive_entry_set_birthtime(e, epochTime, 0); |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // manages the uid/guid of the entry (if any) |
| 494 | if (this->Uid.IsSet() && this->Gid.IsSet()) { |
| 495 | archive_entry_set_uid(e, this->Uid.Get()); |
| 496 | archive_entry_set_gid(e, this->Gid.Get()); |
| 497 | } |
| 498 |
no test coverage detected