| 196 | } |
| 197 | |
| 198 | int32_t ZipWriter::StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, |
| 199 | uint32_t alignment) { |
| 200 | if (state_ != State::kWritingZip) { |
| 201 | return kInvalidState; |
| 202 | } |
| 203 | |
| 204 | if (flags & kAlign32) { |
| 205 | return kInvalidAlign32Flag; |
| 206 | } |
| 207 | |
| 208 | if (powerof2(alignment) == 0) { |
| 209 | return kInvalidAlignment; |
| 210 | } |
| 211 | |
| 212 | FileEntry file_entry = {}; |
| 213 | file_entry.local_file_header_offset = current_offset_; |
| 214 | file_entry.path = path; |
| 215 | |
| 216 | if (!IsValidEntryName(reinterpret_cast<const uint8_t*>(file_entry.path.data()), |
| 217 | file_entry.path.size())) { |
| 218 | return kInvalidEntryName; |
| 219 | } |
| 220 | |
| 221 | if (flags & ZipWriter::kCompress) { |
| 222 | file_entry.compression_method = kCompressDeflated; |
| 223 | |
| 224 | int32_t result = PrepareDeflate(); |
| 225 | if (result != kNoError) { |
| 226 | return result; |
| 227 | } |
| 228 | } else { |
| 229 | file_entry.compression_method = kCompressStored; |
| 230 | } |
| 231 | |
| 232 | ExtractTimeAndDate(time, &file_entry.last_mod_time, &file_entry.last_mod_date); |
| 233 | |
| 234 | off_t offset = current_offset_ + sizeof(LocalFileHeader) + file_entry.path.size(); |
| 235 | std::vector<char> zero_padding; |
| 236 | if (alignment != 0 && (offset & (alignment - 1))) { |
| 237 | // Pad the extra field so the data will be aligned. |
| 238 | uint16_t padding = alignment - (offset % alignment); |
| 239 | file_entry.padding_length = padding; |
| 240 | offset += padding; |
| 241 | zero_padding.resize(padding, 0); |
| 242 | } |
| 243 | |
| 244 | LocalFileHeader header = {}; |
| 245 | // Always start expecting a data descriptor. When the data has finished being written, |
| 246 | // if it is possible to seek back, the GPB flag will reset and the sizes written. |
| 247 | CopyFromFileEntry(file_entry, true /*use_data_descriptor*/, &header); |
| 248 | |
| 249 | if (fwrite(&header, sizeof(header), 1, file_) != 1) { |
| 250 | return HandleError(kIoError); |
| 251 | } |
| 252 | |
| 253 | if (fwrite(path, sizeof(*path), file_entry.path.size(), file_) != file_entry.path.size()) { |
| 254 | return HandleError(kIoError); |
| 255 | } |
nothing calls this directly
no test coverage detected