PackageReaderImpl: Delay reading sections until ParseContent()

This commit is contained in:
Ingo Weinhold 2014-07-13 17:52:13 +02:00
parent 3cc6297e22
commit 43a6b92c64
2 changed files with 27 additions and 13 deletions

View File

@ -67,6 +67,8 @@ private:
friend class PackageWriterImpl; friend class PackageWriterImpl;
private: private:
status_t _PrepareSections();
status_t _ParseTOC(AttributeHandlerContext* context, status_t _ParseTOC(AttributeHandlerContext* context,
AttributeHandler* rootAttributeHandler); AttributeHandler* rootAttributeHandler);

View File

@ -373,15 +373,6 @@ PackageReaderImpl::Init(BPositionIO* file, bool keepFile, uint32 flags,
if (error != B_OK) if (error != B_OK)
return error; 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) if (_header != NULL)
*_header = header; *_header = header;
@ -392,13 +383,16 @@ PackageReaderImpl::Init(BPositionIO* file, bool keepFile, uint32 flags,
status_t status_t
PackageReaderImpl::ParseContent(BPackageContentHandler* contentHandler) PackageReaderImpl::ParseContent(BPackageContentHandler* contentHandler)
{ {
status_t error = _PrepareSections();
if (error != B_OK)
return error;
AttributeHandlerContext context(ErrorOutput(), contentHandler, AttributeHandlerContext context(ErrorOutput(), contentHandler,
B_HPKG_SECTION_PACKAGE_ATTRIBUTES, B_HPKG_SECTION_PACKAGE_ATTRIBUTES,
MinorFormatVersion() > B_HPKG_MINOR_VERSION); MinorFormatVersion() > B_HPKG_MINOR_VERSION);
RootAttributeHandler rootAttributeHandler; RootAttributeHandler rootAttributeHandler;
status_t error error = ParsePackageAttributesSection(&context, &rootAttributeHandler);
= ParsePackageAttributesSection(&context, &rootAttributeHandler);
if (error == B_OK) { if (error == B_OK) {
context.section = B_HPKG_SECTION_PACKAGE_TOC; context.section = B_HPKG_SECTION_PACKAGE_TOC;
@ -412,13 +406,16 @@ PackageReaderImpl::ParseContent(BPackageContentHandler* contentHandler)
status_t status_t
PackageReaderImpl::ParseContent(BLowLevelPackageContentHandler* contentHandler) PackageReaderImpl::ParseContent(BLowLevelPackageContentHandler* contentHandler)
{ {
status_t error = _PrepareSections();
if (error != B_OK)
return error;
AttributeHandlerContext context(ErrorOutput(), contentHandler, AttributeHandlerContext context(ErrorOutput(), contentHandler,
B_HPKG_SECTION_PACKAGE_ATTRIBUTES, B_HPKG_SECTION_PACKAGE_ATTRIBUTES,
MinorFormatVersion() > B_HPKG_MINOR_VERSION); MinorFormatVersion() > B_HPKG_MINOR_VERSION);
LowLevelAttributeHandler rootAttributeHandler; LowLevelAttributeHandler rootAttributeHandler;
status_t error error = ParsePackageAttributesSection(&context, &rootAttributeHandler);
= ParsePackageAttributesSection(&context, &rootAttributeHandler);
if (error == B_OK) { if (error == B_OK) {
context.section = B_HPKG_SECTION_PACKAGE_TOC; 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 status_t
PackageReaderImpl::_ParseTOC(AttributeHandlerContext* context, PackageReaderImpl::_ParseTOC(AttributeHandlerContext* context,
AttributeHandler* rootAttributeHandler) AttributeHandler* rootAttributeHandler)