// Should not happen since we don't have a memory ZipArchive constructor. // However the underlying ZipArchive isn't required to have an FD, // so check to be sure.
CHECK_GE(zip_fd, 0) <<
StringPrintf("Cannot map '%s' (in zip '%s') directly because the zip archive " "is not file backed.",
entry_filename,
zip_filename);
if (!IsUncompressed()) {
*error_msg = StringPrintf("Cannot map '%s' (in zip '%s') directly because it is compressed.",
entry_filename,
zip_filename); return MemMap::Invalid();
} elseif (zip_entry_->uncompressed_length != zip_entry_->compressed_length) {
*error_msg = StringPrintf("Cannot map '%s' (in zip '%s') directly because " "entry has bad size (%u != %u).",
entry_filename,
zip_filename,
zip_entry_->uncompressed_length,
zip_entry_->compressed_length); return MemMap::Invalid();
}
std::string name(entry_filename);
name += " mapped directly in memory from ";
name += zip_filename;
const off_t offset = zip_entry_->offset;
if (kDebugZipMapDirectly) {
LOG(INFO) << "zip_archive: " << "make mmap of " << name << " @ offset = " << offset;
}
if (!map.IsValid()) {
DCHECK(!error_msg->empty());
}
if (kDebugZipMapDirectly) { // Dump contents of file, same format as using this shell command: // $> od -j <offset> -t x1 <zip_filename> static constexpr constint kMaxDumpChars = 15;
lseek(zip_fd, 0, SEEK_SET);
int count = offset + kMaxDumpChars;
std::string tmp; char buf;
// Dump file contents. int i = 0; while (read(zip_fd, &buf, 1) > 0 && i < count) {
tmp += StringPrintf("%3d ", (unsignedint)buf);
++i;
}
LOG(INFO) << "map_fd raw bytes starting at 0";
LOG(INFO) << "" << tmp;
LOG(INFO) << "---------------------------";
// Dump map contents. if (map.IsValid()) {
tmp = "";
count = kMaxDumpChars;
uint8_t* begin = map.Begin(); for (i = 0; i < count; ++i) {
tmp += StringPrintf("%3d ", (unsignedint)begin[i]);
}
// Don't call into `OpenArchive` on file absence. `OpenArchive` prints a warning even if the file // absence is expected. if (!OS::FileExists(filename)) {
*error_msg = StringPrintf("Failed to open '%s': File not found", filename); return nullptr;
}
ZipArchiveHandle handle; const int32_t error = OpenArchive(filename, &handle); if (error != 0) {
*error_msg = StringPrintf("Failed to open '%s': %s", filename, ErrorCodeString(error));
CloseArchive(handle); return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.