Fix problems in repository writer
* actually write the checksum * compress the repository info archive, too (handle it as separate section) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40426 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -36,9 +36,12 @@ public:
|
|||||||
virtual void OnPackageAdded(
|
virtual void OnPackageAdded(
|
||||||
const BPackageInfo& packageInfo) = 0;
|
const BPackageInfo& packageInfo) = 0;
|
||||||
|
|
||||||
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
virtual void OnRepositoryInfoSectionDone(
|
||||||
uint32 uncompressedSize) = 0;
|
uint32 uncompressedSize) = 0;
|
||||||
virtual void OnRepositorySizeInfo(uint32 headerSize,
|
virtual void OnPackageAttributesSectionDone(
|
||||||
|
uint32 stringCount,
|
||||||
|
uint32 uncompressedSize) = 0;
|
||||||
|
virtual void OnRepositoryDone(uint32 headerSize,
|
||||||
uint32 repositoryInfoLength,
|
uint32 repositoryInfoLength,
|
||||||
uint32 packageCount,
|
uint32 packageCount,
|
||||||
uint32 packageAttributesSize,
|
uint32 packageAttributesSize,
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ private:
|
|||||||
status_t _Finish();
|
status_t _Finish();
|
||||||
|
|
||||||
status_t _RegisterCurrentPackageInfo();
|
status_t _RegisterCurrentPackageInfo();
|
||||||
status_t _WriteRepositoryInfo(
|
status_t _WriteRepositoryInfo(hpkg_repo_header& header,
|
||||||
ssize_t& _repositoryInfoLength);
|
ssize_t& _infoLengthCompressed);
|
||||||
off_t _WritePackageAttributes(
|
off_t _WritePackageAttributes(
|
||||||
hpkg_repo_header& header,
|
hpkg_repo_header& header, off_t startOffset,
|
||||||
off_t startOffset);
|
ssize_t& _packagesLengthCompressed);
|
||||||
|
|
||||||
struct PackageNameSet;
|
struct PackageNameSet;
|
||||||
|
|
||||||
|
|||||||
@@ -49,18 +49,19 @@ struct hpkg_repo_header {
|
|||||||
uint32 magic; // "hpkr"
|
uint32 magic; // "hpkr"
|
||||||
uint16 header_size;
|
uint16 header_size;
|
||||||
uint16 version;
|
uint16 version;
|
||||||
uint64 total_size;
|
uint32 total_size;
|
||||||
|
|
||||||
// repository header
|
// repository info section
|
||||||
uint32 repository_header_length;
|
uint32 info_compression;
|
||||||
|
uint32 info_length_compressed;
|
||||||
|
uint32 info_length_uncompressed;
|
||||||
|
|
||||||
// package attributes section
|
// package attributes section
|
||||||
uint32 attributes_compression;
|
uint32 packages_compression;
|
||||||
uint32 attributes_length_compressed;
|
uint32 packages_length_compressed;
|
||||||
uint32 attributes_length_uncompressed;
|
uint32 packages_length_uncompressed;
|
||||||
|
uint32 packages_strings_length;
|
||||||
uint64 attributes_strings_length;
|
uint32 packages_strings_count;
|
||||||
uint64 attributes_strings_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +149,7 @@ enum HPKGPackageAttributeID {
|
|||||||
HPKG_PACKAGE_ATTRIBUTE_FRESHENS,
|
HPKG_PACKAGE_ATTRIBUTE_FRESHENS,
|
||||||
HPKG_PACKAGE_ATTRIBUTE_REPLACES,
|
HPKG_PACKAGE_ATTRIBUTE_REPLACES,
|
||||||
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
||||||
|
HPKG_PACKAGE_ATTRIBUTE_CHECKSUM,
|
||||||
//
|
//
|
||||||
HPKG_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
HPKG_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,9 +48,10 @@ public:
|
|||||||
printf("%s (%s)\n", packageInfo.Name().String(),
|
printf("%s (%s)\n", packageInfo.Name().String(),
|
||||||
packageInfo.Version().ToString().String());
|
packageInfo.Version().ToString().String());
|
||||||
if (fVerbose) {
|
if (fVerbose) {
|
||||||
printf("\tsummary: %s\n", packageInfo.Summary().String());
|
printf("\tsummary: %s\n", packageInfo.Summary().String());
|
||||||
printf("\tvendor: %s\n", packageInfo.Vendor().String());
|
printf("\tvendor: %s\n", packageInfo.Vendor().String());
|
||||||
printf("\tpackager: %s\n", packageInfo.Packager().String());
|
printf("\tpackager: %s\n", packageInfo.Packager().String());
|
||||||
|
printf("\tsha256-checksum: %s\n", packageInfo.Checksum().String());
|
||||||
if (uint32 flags = packageInfo.Flags()) {
|
if (uint32 flags = packageInfo.Flags()) {
|
||||||
printf("\tflags:\n");
|
printf("\tflags:\n");
|
||||||
if ((flags & B_PACKAGE_FLAG_APPROVE_LICENSE) != 0)
|
if ((flags & B_PACKAGE_FLAG_APPROVE_LICENSE) != 0)
|
||||||
@@ -61,21 +62,30 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
virtual void OnRepositoryInfoSectionDone(uint32 uncompressedSize)
|
||||||
|
{
|
||||||
|
if (fQuiet || !fVerbose)
|
||||||
|
return;
|
||||||
|
|
||||||
|
printf("----- Repository Info Section --------------------\n");
|
||||||
|
printf("repository info size: %10lu (uncompressed)\n",
|
||||||
|
uncompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnPackageAttributesSectionDone(uint32 stringCount,
|
||||||
uint32 uncompressedSize)
|
uint32 uncompressedSize)
|
||||||
{
|
{
|
||||||
if (fQuiet || !fVerbose)
|
if (fQuiet || !fVerbose)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("----- Package Attribute Info ---------------------\n");
|
printf("----- Package Attribute Section -------------------\n");
|
||||||
printf("string count: %10lu\n", stringCount);
|
printf("string count: %10lu\n", stringCount);
|
||||||
printf("package attributes size: %10lu (uncompressed)\n",
|
printf("package attributes size: %10lu (uncompressed)\n",
|
||||||
uncompressedSize);
|
uncompressedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnRepositorySizeInfo(uint32 headerSize,
|
virtual void OnRepositoryDone(uint32 headerSize, uint32 repositoryInfoSize,
|
||||||
uint32 repositoryInfoSize, uint32 packageCount,
|
uint32 packageCount, uint32 packageAttributesSize, uint64 totalSize)
|
||||||
uint32 packageAttributesSize, uint64 totalSize)
|
|
||||||
{
|
{
|
||||||
if (fQuiet)
|
if (fQuiet)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -228,28 +228,24 @@ RepositoryWriterImpl::_Finish()
|
|||||||
hpkg_repo_header header;
|
hpkg_repo_header header;
|
||||||
|
|
||||||
// write repository header
|
// write repository header
|
||||||
ssize_t repositoryInfoLength;
|
ssize_t infoLengthCompressed;
|
||||||
status_t result = _WriteRepositoryInfo(repositoryInfoLength);
|
status_t result = _WriteRepositoryInfo(header, infoLengthCompressed);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
header.repository_header_length
|
|
||||||
= B_HOST_TO_BENDIAN_INT32(repositoryInfoLength);
|
|
||||||
|
|
||||||
// write package attributes
|
// write package attributes
|
||||||
|
ssize_t packagesLengthCompressed;
|
||||||
off_t totalSize = _WritePackageAttributes(header,
|
off_t totalSize = _WritePackageAttributes(header,
|
||||||
sizeof(header) + repositoryInfoLength);
|
sizeof(header) + infoLengthCompressed, packagesLengthCompressed);
|
||||||
|
|
||||||
fListener->OnRepositorySizeInfo(sizeof(header), repositoryInfoLength,
|
fListener->OnRepositoryDone(sizeof(header), infoLengthCompressed,
|
||||||
fPackageCount,
|
fPackageCount, packagesLengthCompressed, totalSize);
|
||||||
B_BENDIAN_TO_HOST_INT32(header.attributes_length_compressed),
|
|
||||||
totalSize);
|
|
||||||
|
|
||||||
// general
|
// general
|
||||||
header.magic = B_HOST_TO_BENDIAN_INT32(B_HPKG_REPO_MAGIC);
|
header.magic = B_HOST_TO_BENDIAN_INT32(B_HPKG_REPO_MAGIC);
|
||||||
header.header_size = B_HOST_TO_BENDIAN_INT16((uint16)sizeof(header));
|
header.header_size = B_HOST_TO_BENDIAN_INT16((uint16)sizeof(header));
|
||||||
header.version = B_HOST_TO_BENDIAN_INT16(B_HPKG_REPO_VERSION);
|
header.version = B_HOST_TO_BENDIAN_INT16(B_HPKG_REPO_VERSION);
|
||||||
header.total_size = B_HOST_TO_BENDIAN_INT64(totalSize);
|
header.total_size = B_HOST_TO_BENDIAN_INT32(totalSize);
|
||||||
|
|
||||||
// write the header
|
// write the header
|
||||||
WriteBuffer(&header, sizeof(header), 0);
|
WriteBuffer(&header, sizeof(header), 0);
|
||||||
@@ -350,7 +346,8 @@ RepositoryWriterImpl::_RegisterCurrentPackageInfo()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
RepositoryWriterImpl::_WriteRepositoryInfo(ssize_t& _repositoryInfoLength)
|
RepositoryWriterImpl::_WriteRepositoryInfo(hpkg_repo_header& header,
|
||||||
|
ssize_t& _infoLengthCompressed)
|
||||||
{
|
{
|
||||||
BMessage archive;
|
BMessage archive;
|
||||||
status_t result = fRepositoryInfo->Archive(&archive);
|
status_t result = fRepositoryInfo->Archive(&archive);
|
||||||
@@ -359,22 +356,45 @@ RepositoryWriterImpl::_WriteRepositoryInfo(ssize_t& _repositoryInfoLength)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
_repositoryInfoLength = archive.FlattenedSize();
|
ssize_t flattenedSize = archive.FlattenedSize();
|
||||||
char buffer[_repositoryInfoLength];
|
char buffer[flattenedSize];
|
||||||
if ((result = archive.Flatten(buffer, _repositoryInfoLength)) != B_OK) {
|
if ((result = archive.Flatten(buffer, flattenedSize)) != B_OK) {
|
||||||
fListener->PrintError("can't flatten repository header!\n");
|
fListener->PrintError("can't flatten repository header!\n");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t startOffset = sizeof(hpkg_repo_header);
|
off_t startOffset = sizeof(hpkg_repo_header);
|
||||||
WriteBuffer(buffer, _repositoryInfoLength, startOffset);
|
|
||||||
|
// write the package attributes (zlib writer on top of a file writer)
|
||||||
|
FDDataWriter realWriter(FD(), startOffset, fListener);
|
||||||
|
ZlibDataWriter zlibWriter(&realWriter);
|
||||||
|
SetDataWriter(&zlibWriter);
|
||||||
|
zlibWriter.Init();
|
||||||
|
|
||||||
|
DataWriter()->WriteDataThrows(buffer, flattenedSize);
|
||||||
|
|
||||||
|
zlibWriter.Finish();
|
||||||
|
SetDataWriter(NULL);
|
||||||
|
|
||||||
|
fListener->OnRepositoryInfoSectionDone(zlibWriter.BytesWritten());
|
||||||
|
|
||||||
|
_infoLengthCompressed = realWriter.BytesWritten();
|
||||||
|
|
||||||
|
// update the header
|
||||||
|
header.info_compression
|
||||||
|
= B_HOST_TO_BENDIAN_INT32(B_HPKG_COMPRESSION_ZLIB);
|
||||||
|
header.info_length_compressed
|
||||||
|
= B_HOST_TO_BENDIAN_INT32(_infoLengthCompressed);
|
||||||
|
header.info_length_uncompressed
|
||||||
|
= B_HOST_TO_BENDIAN_INT32(flattenedSize);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
off_t
|
off_t
|
||||||
RepositoryWriterImpl::_WritePackageAttributes(hpkg_repo_header& header,
|
RepositoryWriterImpl::_WritePackageAttributes(hpkg_repo_header& header,
|
||||||
off_t startOffset)
|
off_t startOffset, ssize_t& _packagesLengthCompressed)
|
||||||
{
|
{
|
||||||
// write the package attributes (zlib writer on top of a file writer)
|
// write the package attributes (zlib writer on top of a file writer)
|
||||||
FDDataWriter realWriter(FD(), startOffset, fListener);
|
FDDataWriter realWriter(FD(), startOffset, fListener);
|
||||||
@@ -391,18 +411,20 @@ RepositoryWriterImpl::_WritePackageAttributes(hpkg_repo_header& header,
|
|||||||
off_t endOffset = realWriter.Offset();
|
off_t endOffset = realWriter.Offset();
|
||||||
SetDataWriter(NULL);
|
SetDataWriter(NULL);
|
||||||
|
|
||||||
fListener->OnPackageAttributesSizeInfo(stringsCount,
|
fListener->OnPackageAttributesSectionDone(stringsCount,
|
||||||
zlibWriter.BytesWritten());
|
zlibWriter.BytesWritten());
|
||||||
|
|
||||||
|
_packagesLengthCompressed = endOffset - startOffset;
|
||||||
|
|
||||||
// update the header
|
// update the header
|
||||||
header.attributes_compression
|
header.packages_compression
|
||||||
= B_HOST_TO_BENDIAN_INT32(B_HPKG_COMPRESSION_ZLIB);
|
= B_HOST_TO_BENDIAN_INT32(B_HPKG_COMPRESSION_ZLIB);
|
||||||
header.attributes_length_compressed
|
header.packages_length_compressed
|
||||||
= B_HOST_TO_BENDIAN_INT32(endOffset - startOffset);
|
= B_HOST_TO_BENDIAN_INT32(_packagesLengthCompressed);
|
||||||
header.attributes_length_uncompressed
|
header.packages_length_uncompressed
|
||||||
= B_HOST_TO_BENDIAN_INT32(zlibWriter.BytesWritten());
|
= B_HOST_TO_BENDIAN_INT32(zlibWriter.BytesWritten());
|
||||||
header.attributes_strings_count = B_HOST_TO_BENDIAN_INT32(stringsCount);
|
header.packages_strings_count = B_HOST_TO_BENDIAN_INT32(stringsCount);
|
||||||
header.attributes_strings_length
|
header.packages_strings_length
|
||||||
= B_HOST_TO_BENDIAN_INT32(stringsLengthUncompressed);
|
= B_HOST_TO_BENDIAN_INT32(stringsLengthUncompressed);
|
||||||
|
|
||||||
return endOffset;
|
return endOffset;
|
||||||
|
|||||||
@@ -479,6 +479,16 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
= fPackageStringCache.Get(replacesList.ItemAt(i)->String());
|
= fPackageStringCache.Get(replacesList.ItemAt(i)->String());
|
||||||
attributeList.Add(replaces);
|
attributeList.Add(replaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checksum (optional, only exists in repositories)
|
||||||
|
if (packageInfo.Checksum().Length() > 0) {
|
||||||
|
PackageAttribute* checksum = new PackageAttribute(
|
||||||
|
HPKG_PACKAGE_ATTRIBUTE_CHECKSUM, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
|
checksum->string
|
||||||
|
= fPackageStringCache.Get(packageInfo.Checksum().String());
|
||||||
|
attributeList.Add(checksum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user