From 43a6b92c6424ae5976e467571e6edd7e60354110 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 13 Jul 2014 17:52:13 +0200 Subject: [PATCH] PackageReaderImpl: Delay reading sections until ParseContent() --- .../private/package/hpkg/PackageReaderImpl.h | 2 + src/kits/package/hpkg/PackageReaderImpl.cpp | 38 ++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/headers/private/package/hpkg/PackageReaderImpl.h b/headers/private/package/hpkg/PackageReaderImpl.h index 37cdb344b5..121991233c 100644 --- a/headers/private/package/hpkg/PackageReaderImpl.h +++ b/headers/private/package/hpkg/PackageReaderImpl.h @@ -67,6 +67,8 @@ private: friend class PackageWriterImpl; private: + status_t _PrepareSections(); + status_t _ParseTOC(AttributeHandlerContext* context, AttributeHandler* rootAttributeHandler); diff --git a/src/kits/package/hpkg/PackageReaderImpl.cpp b/src/kits/package/hpkg/PackageReaderImpl.cpp index 1ff2bf2d29..ac04ccd53c 100644 --- a/src/kits/package/hpkg/PackageReaderImpl.cpp +++ b/src/kits/package/hpkg/PackageReaderImpl.cpp @@ -373,15 +373,6 @@ PackageReaderImpl::Init(BPositionIO* file, bool keepFile, uint32 flags, if (error != B_OK) return error; - // prepare the sections for use - error = PrepareSection(fTOCSection); - if (error != B_OK) - return error; - - error = PrepareSection(fPackageAttributesSection); - if (error != B_OK) - return error; - if (_header != NULL) *_header = header; @@ -392,13 +383,16 @@ PackageReaderImpl::Init(BPositionIO* file, bool keepFile, uint32 flags, status_t PackageReaderImpl::ParseContent(BPackageContentHandler* contentHandler) { + status_t error = _PrepareSections(); + if (error != B_OK) + return error; + AttributeHandlerContext context(ErrorOutput(), contentHandler, B_HPKG_SECTION_PACKAGE_ATTRIBUTES, MinorFormatVersion() > B_HPKG_MINOR_VERSION); RootAttributeHandler rootAttributeHandler; - status_t error - = ParsePackageAttributesSection(&context, &rootAttributeHandler); + error = ParsePackageAttributesSection(&context, &rootAttributeHandler); if (error == B_OK) { context.section = B_HPKG_SECTION_PACKAGE_TOC; @@ -412,13 +406,16 @@ PackageReaderImpl::ParseContent(BPackageContentHandler* contentHandler) status_t PackageReaderImpl::ParseContent(BLowLevelPackageContentHandler* contentHandler) { + status_t error = _PrepareSections(); + if (error != B_OK) + return error; + AttributeHandlerContext context(ErrorOutput(), contentHandler, B_HPKG_SECTION_PACKAGE_ATTRIBUTES, MinorFormatVersion() > B_HPKG_MINOR_VERSION); LowLevelAttributeHandler rootAttributeHandler; - status_t error - = ParsePackageAttributesSection(&context, &rootAttributeHandler); + error = ParsePackageAttributesSection(&context, &rootAttributeHandler); if (error == B_OK) { context.section = B_HPKG_SECTION_PACKAGE_TOC; @@ -429,6 +426,21 @@ PackageReaderImpl::ParseContent(BLowLevelPackageContentHandler* contentHandler) } +status_t +PackageReaderImpl::_PrepareSections() +{ + status_t error = PrepareSection(fTOCSection); + if (error != B_OK) + return error; + + error = PrepareSection(fPackageAttributesSection); + if (error != B_OK) + return error; + + return B_OK; +} + + status_t PackageReaderImpl::_ParseTOC(AttributeHandlerContext* context, AttributeHandler* rootAttributeHandler)