| 92 | }; |
| 93 | |
| 94 | cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, |
| 95 | std::string const& format, int compressionLevel, |
| 96 | int numThreads) |
| 97 | : Stream(os) |
| 98 | , Archive(archive_write_new()) |
| 99 | , Disk(archive_read_disk_new()) |
| 100 | , Format(format) |
| 101 | { |
| 102 | // Upstream fixed an issue with their integer parsing in 3.4.0 |
| 103 | // which would cause spurious errors to be raised from `strtoull`. |
| 104 | |
| 105 | if (archive_write_set_format_by_name(this->Archive, format.c_str()) != |
| 106 | ARCHIVE_OK) { |
| 107 | this->Error = cmStrCat("archive_write_set_format_by_name: ", |
| 108 | cm_archive_error_string(this->Archive)); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | bool is7zip = (format == "7zip"); |
| 113 | bool isZip = (format == "zip"); |
| 114 | bool isFormatSupportsCompressionNatively = (is7zip || isZip); |
| 115 | |
| 116 | if (numThreads < 1) { |
| 117 | int upperLimit = (numThreads == 0) ? std::numeric_limits<int>::max() |
| 118 | : std::abs(numThreads); |
| 119 | |
| 120 | numThreads = |
| 121 | cm::clamp<int>(std::thread::hardware_concurrency(), 1, upperLimit); |
| 122 | } |
| 123 | |
| 124 | std::string sNumThreads = std::to_string(numThreads); |
| 125 | |
| 126 | if (!isFormatSupportsCompressionNatively) { |
| 127 | switch (c) { |
| 128 | case CompressNone: |
| 129 | if (archive_write_add_filter_none(this->Archive) != ARCHIVE_OK) { |
| 130 | this->Error = cmStrCat("archive_write_add_filter_none: ", |
| 131 | cm_archive_error_string(this->Archive)); |
| 132 | return; |
| 133 | } |
| 134 | break; |
| 135 | case CompressCompress: |
| 136 | if (archive_write_add_filter_compress(this->Archive) != ARCHIVE_OK) { |
| 137 | this->Error = cmStrCat("archive_write_add_filter_compress: ", |
| 138 | cm_archive_error_string(this->Archive)); |
| 139 | return; |
| 140 | } |
| 141 | break; |
| 142 | case CompressGZip: { |
| 143 | if (archive_write_add_filter_gzip(this->Archive) != ARCHIVE_OK) { |
| 144 | this->Error = cmStrCat("archive_write_add_filter_gzip: ", |
| 145 | cm_archive_error_string(this->Archive)); |
| 146 | return; |
| 147 | } |
| 148 | std::string source_date_epoch; |
| 149 | cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch); |
| 150 | if (!source_date_epoch.empty()) { |
| 151 | // We're not able to specify an arbitrary timestamp for gzip. |
nothing calls this directly
no test coverage detected