Largish adjustments to PackagerReaderImpl and package attribute
handling: * package attributes are now compatible with the low level attribute handling of other HPKG attributes (such that 'package dump' now shows package attributes, too) * dropped type names from hpkg format, the attributes were identified by IDs already and this simplifies the code considerably. Type names are now handled in BLowLevelPackageHandler only. * instead of rolling their own mechanism, high-level package attributes handling is now implemented via a corresonding set of AttributeHandler-subclasses * adjusted package writer to only write package attributes that are needed (empty ones are left out) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40466 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
enum BPackageInfoAttributeIndex {
|
enum BPackageInfoAttributeID {
|
||||||
B_PACKAGE_INFO_NAME = 0,
|
B_PACKAGE_INFO_NAME = 0,
|
||||||
B_PACKAGE_INFO_SUMMARY, // single line
|
B_PACKAGE_INFO_SUMMARY, // single line
|
||||||
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
|
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
|
||||||
|
|||||||
@@ -69,29 +69,49 @@ enum {
|
|||||||
|
|
||||||
|
|
||||||
// package attribute IDs
|
// package attribute IDs
|
||||||
enum BPackageAttributeID {
|
enum BHPKGAttributeID {
|
||||||
B_PACKAGE_ATTRIBUTE_NAME = 0,
|
B_HPKG_ATTRIBUTE_ID_DIRECTORY_ENTRY = 0,
|
||||||
B_PACKAGE_ATTRIBUTE_SUMMARY,
|
B_HPKG_ATTRIBUTE_ID_FILE_TYPE = 1,
|
||||||
B_PACKAGE_ATTRIBUTE_DESCRIPTION,
|
B_HPKG_ATTRIBUTE_ID_FILE_PERMISSIONS = 2,
|
||||||
B_PACKAGE_ATTRIBUTE_VENDOR,
|
B_HPKG_ATTRIBUTE_ID_FILE_USER = 3,
|
||||||
B_PACKAGE_ATTRIBUTE_PACKAGER,
|
B_HPKG_ATTRIBUTE_ID_FILE_GROUP = 4,
|
||||||
B_PACKAGE_ATTRIBUTE_ARCHITECTURE,
|
B_HPKG_ATTRIBUTE_ID_FILE_ATIME = 5,
|
||||||
B_PACKAGE_ATTRIBUTE_VERSION_MAJOR,
|
B_HPKG_ATTRIBUTE_ID_FILE_MTIME = 6,
|
||||||
B_PACKAGE_ATTRIBUTE_VERSION_MINOR,
|
B_HPKG_ATTRIBUTE_ID_FILE_CRTIME = 7,
|
||||||
B_PACKAGE_ATTRIBUTE_VERSION_MICRO,
|
B_HPKG_ATTRIBUTE_ID_FILE_ATIME_NANOS = 8,
|
||||||
B_PACKAGE_ATTRIBUTE_VERSION_RELEASE,
|
B_HPKG_ATTRIBUTE_ID_FILE_MTIME_NANOS = 9,
|
||||||
B_PACKAGE_ATTRIBUTE_COPYRIGHT,
|
B_HPKG_ATTRIBUTE_ID_FILE_CRTIM_NANOS = 10,
|
||||||
B_PACKAGE_ATTRIBUTE_LICENSE,
|
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE = 11,
|
||||||
B_PACKAGE_ATTRIBUTE_PROVIDES,
|
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE_TYPE = 12,
|
||||||
B_PACKAGE_ATTRIBUTE_PROVIDES_TYPE,
|
B_HPKG_ATTRIBUTE_ID_DATA = 13,
|
||||||
B_PACKAGE_ATTRIBUTE_REQUIRES,
|
B_HPKG_ATTRIBUTE_ID_DATA_SIZE = 14,
|
||||||
B_PACKAGE_ATTRIBUTE_SUPPLEMENTS,
|
B_HPKG_ATTRIBUTE_ID_DATA_COMPRESSION = 15,
|
||||||
B_PACKAGE_ATTRIBUTE_CONFLICTS,
|
B_HPKG_ATTRIBUTE_ID_DATA_CHUNK_SIZE = 16,
|
||||||
B_PACKAGE_ATTRIBUTE_FRESHENS,
|
B_HPKG_ATTRIBUTE_ID_SYMLINK_PATH = 17,
|
||||||
B_PACKAGE_ATTRIBUTE_REPLACES,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_NAME = 18,
|
||||||
B_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_SUMMARY = 19,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_DESCRIPTION = 20,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VENDOR = 21,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PACKAGER = 22,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_FLAGS = 23,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_ARCHITECTURE = 24,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MAJOR = 25,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MINOR = 26,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MICRO = 27,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_RELEASE = 28,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_COPYRIGHT = 29,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_LICENSE = 30,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES = 31,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES_TYPE = 32,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_REQUIRES = 33,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_SUPPLEMENTS = 34,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_CONFLICTS = 35,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_FRESHENS = 36,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_REPLACES = 37,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_RESOLVABLE_OPERATOR = 38,
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_CHECKSUM = 39,
|
||||||
//
|
//
|
||||||
B_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
B_HPKG_ATTRIBUTE_ID_ENUM_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +122,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// file types (HPKG_ATTRIBUTE_NAME_FILE_TYPE)
|
// file types (B_HPKG_ATTRIBUTE_ID_FILE_TYPE)
|
||||||
enum {
|
enum {
|
||||||
B_HPKG_FILE_TYPE_FILE = 0,
|
B_HPKG_FILE_TYPE_FILE = 0,
|
||||||
B_HPKG_FILE_TYPE_DIRECTORY = 1,
|
B_HPKG_FILE_TYPE_DIRECTORY = 1,
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include <package/hpkg/HPKGDefs.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|
||||||
@@ -24,14 +26,18 @@ class BLowLevelPackageContentHandler {
|
|||||||
public:
|
public:
|
||||||
virtual ~BLowLevelPackageContentHandler();
|
virtual ~BLowLevelPackageContentHandler();
|
||||||
|
|
||||||
virtual status_t HandleAttribute(const char* attributeName,
|
virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
|
||||||
const BPackageAttributeValue& value,
|
const BPackageAttributeValue& value,
|
||||||
void* parentToken, void*& _token) = 0;
|
void* parentToken, void*& _token) = 0;
|
||||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
virtual status_t HandleAttributeDone(
|
||||||
|
BHPKGAttributeID attributeID,
|
||||||
const BPackageAttributeValue& value,
|
const BPackageAttributeValue& value,
|
||||||
void* token) = 0;
|
void* token) = 0;
|
||||||
|
|
||||||
virtual void HandleErrorOccurred() = 0;
|
virtual void HandleErrorOccurred() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static const char* AttributeNameForID(uint8 id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +53,6 @@ public:
|
|||||||
virtual status_t HandlePackageAttribute(
|
virtual status_t HandlePackageAttribute(
|
||||||
const BPackageInfoAttributeValue& value
|
const BPackageInfoAttributeValue& value
|
||||||
) = 0;
|
) = 0;
|
||||||
virtual status_t HandlePackageAttributesDone() = 0;
|
|
||||||
|
|
||||||
virtual void HandleErrorOccurred() = 0;
|
virtual void HandleErrorOccurred() = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,42 +51,52 @@ struct BPackageInfoAttributeValue {
|
|||||||
BPackageResolvableData resolvable;
|
BPackageResolvableData resolvable;
|
||||||
BPackageResolvableExpressionData resolvableExpression;
|
BPackageResolvableExpressionData resolvableExpression;
|
||||||
};
|
};
|
||||||
uint8 attributeIndex;
|
BPackageInfoAttributeID attributeID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline BPackageInfoAttributeValue();
|
BPackageInfoAttributeValue();
|
||||||
|
|
||||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
void SetTo(BPackageInfoAttributeID id,
|
||||||
uint8 value);
|
uint8 value);
|
||||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
void SetTo(BPackageInfoAttributeID id,
|
||||||
const char* value);
|
const char* value);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline
|
||||||
BPackageInfoAttributeValue::BPackageInfoAttributeValue()
|
BPackageInfoAttributeValue::BPackageInfoAttributeValue()
|
||||||
:
|
|
||||||
attributeIndex(B_PACKAGE_INFO_ENUM_COUNT)
|
|
||||||
{
|
{
|
||||||
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
inline void
|
||||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index, uint8 value)
|
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, uint8 value)
|
||||||
{
|
{
|
||||||
attributeIndex = index;
|
attributeID = id;
|
||||||
unsignedInt = value;
|
unsignedInt = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
inline void
|
||||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index,
|
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id,
|
||||||
const char* value)
|
const char* value)
|
||||||
{
|
{
|
||||||
attributeIndex = index;
|
attributeID = id;
|
||||||
string = value;
|
string = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void
|
||||||
|
BPackageInfoAttributeValue::Clear()
|
||||||
|
{
|
||||||
|
memset(this, 0, sizeof(BPackageInfoAttributeValue));
|
||||||
|
attributeID = B_PACKAGE_INFO_ENUM_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BHPKG
|
} // namespace BHPKG
|
||||||
|
|
||||||
} // namespace BPackageKit
|
} // namespace BPackageKit
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ public:
|
|||||||
|
|
||||||
virtual void OnEntryAdded(const char* path) = 0;
|
virtual void OnEntryAdded(const char* path) = 0;
|
||||||
|
|
||||||
virtual void OnTOCSizeInfo(
|
virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
|
||||||
uint64 uncompressedAttributeTypesSize,
|
|
||||||
uint64 uncompressedStringsSize,
|
|
||||||
uint64 uncompressedMainSize,
|
uint64 uncompressedMainSize,
|
||||||
uint64 uncompressedTOCSize) = 0;
|
uint64 uncompressedTOCSize) = 0;
|
||||||
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||||
|
#define _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
class BPackageInfo;
|
||||||
|
class BRepositoryInfo;
|
||||||
|
|
||||||
|
|
||||||
|
namespace BHPKG {
|
||||||
|
|
||||||
|
|
||||||
|
class BRepositoryContentHandler {
|
||||||
|
public:
|
||||||
|
virtual ~BRepositoryContentHandler();
|
||||||
|
|
||||||
|
virtual status_t HandleRepositoryInfo(
|
||||||
|
const BRepositoryInfo& info) = 0;
|
||||||
|
virtual status_t HandlePackage(const BPackageInfo& info) = 0;
|
||||||
|
virtual status_t HandlePackagesDone() = 0;
|
||||||
|
|
||||||
|
virtual void HandleErrorOccurred() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BHPKG
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__HPKG__REPOSITORY_CONTENT_HANDLER_H_
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Haiku, Inc.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||||
|
#define _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BHPKG {
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
class RepositoryReaderImpl;
|
||||||
|
}
|
||||||
|
using BPrivate::RepositoryReaderImpl;
|
||||||
|
|
||||||
|
class BErrorOutput;
|
||||||
|
class BRepositoryContentHandler;
|
||||||
|
|
||||||
|
|
||||||
|
class BRepositoryReader {
|
||||||
|
public:
|
||||||
|
BRepositoryReader(BErrorOutput* errorOutput);
|
||||||
|
~BRepositoryReader();
|
||||||
|
|
||||||
|
status_t Init(const char* fileName);
|
||||||
|
status_t ParseContent(
|
||||||
|
BPackageContentHandler* contentHandler);
|
||||||
|
|
||||||
|
private:
|
||||||
|
RepositoryReaderImpl* fImpl;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BHPKG
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__HPKG__REPOSITORY_READER_H_
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||||
|
#define _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include <package/hpkg/HPKGDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BHPKG {
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
// header
|
||||||
|
struct hpkg_header {
|
||||||
|
uint32 magic; // "hpkg"
|
||||||
|
uint16 header_size;
|
||||||
|
uint16 version;
|
||||||
|
uint64 total_size;
|
||||||
|
|
||||||
|
// package attributes section
|
||||||
|
uint32 attributes_compression;
|
||||||
|
uint32 attributes_length_compressed;
|
||||||
|
uint32 attributes_length_uncompressed;
|
||||||
|
uint32 attributes_strings_length;
|
||||||
|
uint32 attributes_strings_count;
|
||||||
|
|
||||||
|
// TOC section
|
||||||
|
uint32 toc_compression;
|
||||||
|
uint64 toc_length_compressed;
|
||||||
|
uint64 toc_length_uncompressed;
|
||||||
|
uint64 toc_strings_length;
|
||||||
|
uint64 toc_strings_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// header
|
||||||
|
struct hpkg_repo_header {
|
||||||
|
uint32 magic; // "hpkr"
|
||||||
|
uint16 header_size;
|
||||||
|
uint16 version;
|
||||||
|
uint32 total_size;
|
||||||
|
|
||||||
|
// repository info section
|
||||||
|
uint32 info_compression;
|
||||||
|
uint32 info_length_compressed;
|
||||||
|
uint32 info_length_uncompressed;
|
||||||
|
|
||||||
|
// package attributes section
|
||||||
|
uint32 packages_compression;
|
||||||
|
uint32 packages_length_compressed;
|
||||||
|
uint32 packages_length_uncompressed;
|
||||||
|
uint32 packages_strings_length;
|
||||||
|
uint32 packages_strings_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// attribute tag arithmetics
|
||||||
|
// (using 6 bits for id, 3 for type, 1 for hasChildren and 2 for encoding)
|
||||||
|
#define HPKG_ATTRIBUTE_TAG_COMPOSE(id, type, encoding, hasChildren) \
|
||||||
|
(((uint16(encoding) << 10) | (uint16((hasChildren) ? 1 : 0) << 9) \
|
||||||
|
| (uint16(type) << 6) | (uint16(id))) + 1)
|
||||||
|
#define HPKG_ATTRIBUTE_TAG_ENCODING(tag) \
|
||||||
|
((uint16((tag) - 1) >> 10) & 0x3)
|
||||||
|
#define HPKG_ATTRIBUTE_TAG_HAS_CHILDREN(tag) \
|
||||||
|
(((uint16((tag) - 1) >> 9) & 0x1) != 0)
|
||||||
|
#define HPKG_ATTRIBUTE_TAG_TYPE(tag) \
|
||||||
|
((uint16((tag) - 1) >> 6) & 0x7)
|
||||||
|
#define HPKG_ATTRIBUTE_TAG_ID(tag) \
|
||||||
|
(uint16((tag) - 1) & 0x3f)
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
} // namespace BHPKG
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
||||||
@@ -46,16 +46,18 @@ public:
|
|||||||
int PackageFileFD() { return fFD; }
|
int PackageFileFD() { return fFD; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct AttributeType;
|
|
||||||
struct AttributeTypeReference;
|
|
||||||
struct AttributeHandlerContext;
|
struct AttributeHandlerContext;
|
||||||
struct AttributeHandler;
|
struct AttributeHandler;
|
||||||
struct IgnoreAttributeHandler;
|
struct IgnoreAttributeHandler;
|
||||||
struct DataAttributeHandler;
|
struct DataAttributeHandler;
|
||||||
struct AttributeAttributeHandler;
|
struct AttributeAttributeHandler;
|
||||||
struct EntryAttributeHandler;
|
struct EntryAttributeHandler;
|
||||||
struct RootAttributeHandler;
|
|
||||||
struct PackageAttributeHandler;
|
struct PackageAttributeHandler;
|
||||||
|
struct PackageVersionAttributeHandler;
|
||||||
|
struct PackageResolvableAttributeHandler;
|
||||||
|
struct PackageResolvableExpressionAttributeHandler;
|
||||||
|
struct RootAttributeHandler;
|
||||||
|
struct LowLevelAttributeHandler;
|
||||||
struct PackageContentListHandler;
|
struct PackageContentListHandler;
|
||||||
|
|
||||||
struct SectionInfo {
|
struct SectionInfo {
|
||||||
@@ -94,8 +96,6 @@ private:
|
|||||||
const char* _CheckCompression(
|
const char* _CheckCompression(
|
||||||
const SectionInfo& section) const;
|
const SectionInfo& section) const;
|
||||||
|
|
||||||
status_t _ParseTOCAttributeTypes();
|
|
||||||
|
|
||||||
status_t _ParseStrings();
|
status_t _ParseStrings();
|
||||||
|
|
||||||
status_t _ParseContent(AttributeHandlerContext* context,
|
status_t _ParseContent(AttributeHandlerContext* context,
|
||||||
@@ -117,7 +117,7 @@ private:
|
|||||||
const char* resolvableName,
|
const char* resolvableName,
|
||||||
bool hasChildren);
|
bool hasChildren);
|
||||||
|
|
||||||
status_t _ReadPackageAttribute(uint8& _id,
|
status_t _ReadAttribute(uint8& _id,
|
||||||
AttributeValue& _value,
|
AttributeValue& _value,
|
||||||
bool* _hasChildren = NULL,
|
bool* _hasChildren = NULL,
|
||||||
uint64* _tag = NULL);
|
uint64* _tag = NULL);
|
||||||
@@ -141,8 +141,6 @@ private:
|
|||||||
status_t _ReadCompressedBuffer(
|
status_t _ReadCompressedBuffer(
|
||||||
const SectionInfo& section);
|
const SectionInfo& section);
|
||||||
|
|
||||||
static int8 _GetStandardIndex(const AttributeType* type);
|
|
||||||
|
|
||||||
inline AttributeHandler* _CurrentAttributeHandler() const;
|
inline AttributeHandler* _CurrentAttributeHandler() const;
|
||||||
inline void _PushAttributeHandler(
|
inline void _PushAttributeHandler(
|
||||||
AttributeHandler* handler);
|
AttributeHandler* handler);
|
||||||
@@ -157,15 +155,10 @@ private:
|
|||||||
uint64 fHeapOffset;
|
uint64 fHeapOffset;
|
||||||
uint64 fHeapSize;
|
uint64 fHeapSize;
|
||||||
|
|
||||||
uint64 fTOCAttributeTypesLength;
|
|
||||||
uint64 fTOCAttributeTypesCount;
|
|
||||||
|
|
||||||
SectionInfo fTOCSection;
|
SectionInfo fTOCSection;
|
||||||
SectionInfo fPackageAttributesSection;
|
SectionInfo fPackageAttributesSection;
|
||||||
SectionInfo* fCurrentSection;
|
SectionInfo* fCurrentSection;
|
||||||
|
|
||||||
AttributeTypeReference* fAttributeTypes;
|
|
||||||
|
|
||||||
AttributeHandlerList* fAttributeHandlerStack;
|
AttributeHandlerList* fAttributeHandlerStack;
|
||||||
|
|
||||||
uint8* fScratchBuffer;
|
uint8* fScratchBuffer;
|
||||||
|
|||||||
@@ -42,16 +42,10 @@ public:
|
|||||||
status_t Finish();
|
status_t Finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct AttributeTypeKey;
|
|
||||||
struct AttributeType;
|
|
||||||
struct AttributeTypeHashDefinition;
|
|
||||||
struct Attribute;
|
struct Attribute;
|
||||||
struct AttributeTypeUsageGreater;
|
|
||||||
struct Entry;
|
struct Entry;
|
||||||
struct SubPathAdder;
|
struct SubPathAdder;
|
||||||
|
|
||||||
typedef BOpenHashTable<AttributeTypeHashDefinition>
|
|
||||||
AttributeTypeTable;
|
|
||||||
typedef DoublyLinkedList<Entry> EntryList;
|
typedef DoublyLinkedList<Entry> EntryList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -66,9 +60,8 @@ private:
|
|||||||
status_t _CheckLicenses();
|
status_t _CheckLicenses();
|
||||||
|
|
||||||
void _WriteTOC(hpkg_header& header);
|
void _WriteTOC(hpkg_header& header);
|
||||||
int32 _WriteTOCSections(uint64& _attributeTypesSize,
|
int32 _WriteTOCSections(uint64& _stringsSize,
|
||||||
uint64& _stringsSize, uint64& _mainSize);
|
uint64& _mainSize);
|
||||||
void _WriteAttributeTypes();
|
|
||||||
void _WriteAttributeChildren(Attribute* attribute);
|
void _WriteAttributeChildren(Attribute* attribute);
|
||||||
|
|
||||||
void _WritePackageAttributes(hpkg_header& header);
|
void _WritePackageAttributes(hpkg_header& header);
|
||||||
@@ -76,23 +69,21 @@ private:
|
|||||||
void _AddEntry(int dirFD, Entry* entry,
|
void _AddEntry(int dirFD, Entry* entry,
|
||||||
const char* fileName, char* pathBuffer);
|
const char* fileName, char* pathBuffer);
|
||||||
|
|
||||||
Attribute* _AddAttribute(const char* attributeName,
|
Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||||
const AttributeValue& value);
|
const AttributeValue& value);
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline Attribute* _AddAttribute(const char* attributeName,
|
inline Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||||
Type value);
|
Type value);
|
||||||
|
|
||||||
Attribute* _AddStringAttribute(const char* attributeName,
|
Attribute* _AddStringAttribute(
|
||||||
|
BHPKGAttributeID attributeID,
|
||||||
const char* value);
|
const char* value);
|
||||||
Attribute* _AddDataAttribute(const char* attributeName,
|
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||||
uint64 dataSize, uint64 dataOffset);
|
uint64 dataSize, uint64 dataOffset);
|
||||||
Attribute* _AddDataAttribute(const char* attributeName,
|
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||||
uint64 dataSize, const uint8* data);
|
uint64 dataSize, const uint8* data);
|
||||||
|
|
||||||
AttributeType* _GetAttributeType(const char* attributeName,
|
|
||||||
uint8 type);
|
|
||||||
|
|
||||||
status_t _AddData(BDataReader& dataReader, off_t size);
|
status_t _AddData(BDataReader& dataReader, off_t size);
|
||||||
|
|
||||||
status_t _WriteUncompressedData(BDataReader& dataReader,
|
status_t _WriteUncompressedData(BDataReader& dataReader,
|
||||||
@@ -117,7 +108,6 @@ private:
|
|||||||
Attribute* fTopAttribute;
|
Attribute* fTopAttribute;
|
||||||
|
|
||||||
StringCache fStringCache;
|
StringCache fStringCache;
|
||||||
AttributeTypeTable* fAttributeTypes;
|
|
||||||
|
|
||||||
BPackageInfo fPackageInfo;
|
BPackageInfo fPackageInfo;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||||
|
#define _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include <util/SinglyLinkedList.h>
|
||||||
|
|
||||||
|
#include <package/hpkg/PackageAttributeValue.h>
|
||||||
|
#include <package/hpkg/PackageContentHandler.h>
|
||||||
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||||
|
#include <package/hpkg/PackageReader.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BHPKG {
|
||||||
|
|
||||||
|
|
||||||
|
class BPackageEntry;
|
||||||
|
class BPackageEntryAttribute;
|
||||||
|
class BErrorOutput;
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
class PackageReaderImpl {
|
||||||
|
public:
|
||||||
|
PackageReaderImpl(
|
||||||
|
BErrorOutput* errorOutput);
|
||||||
|
~PackageReaderImpl();
|
||||||
|
|
||||||
|
status_t Init(const char* fileName);
|
||||||
|
status_t Init(int fd, bool keepFD);
|
||||||
|
status_t ParseContent(
|
||||||
|
BPackageContentHandler* contentHandler);
|
||||||
|
status_t ParseContent(BLowLevelPackageContentHandler*
|
||||||
|
contentHandler);
|
||||||
|
|
||||||
|
int PackageFileFD() { return fFD; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct AttributeType;
|
||||||
|
struct AttributeTypeReference;
|
||||||
|
struct AttributeHandlerContext;
|
||||||
|
struct AttributeHandler;
|
||||||
|
struct IgnoreAttributeHandler;
|
||||||
|
struct DataAttributeHandler;
|
||||||
|
struct AttributeAttributeHandler;
|
||||||
|
struct EntryAttributeHandler;
|
||||||
|
struct RootAttributeHandler;
|
||||||
|
struct PackageAttributeHandler;
|
||||||
|
struct PackageContentListHandler;
|
||||||
|
|
||||||
|
struct SectionInfo {
|
||||||
|
uint32 compression;
|
||||||
|
uint32 compressedLength;
|
||||||
|
uint32 uncompressedLength;
|
||||||
|
uint8* data;
|
||||||
|
uint64 offset;
|
||||||
|
uint64 currentOffset;
|
||||||
|
uint64 stringsLength;
|
||||||
|
uint64 stringsCount;
|
||||||
|
char** strings;
|
||||||
|
const char* name;
|
||||||
|
|
||||||
|
SectionInfo(const char* _name)
|
||||||
|
:
|
||||||
|
data(NULL),
|
||||||
|
strings(NULL),
|
||||||
|
name(_name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~SectionInfo()
|
||||||
|
{
|
||||||
|
delete[] strings;
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef BPackageAttributeValue AttributeValue;
|
||||||
|
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _Init(const char* fileName);
|
||||||
|
|
||||||
|
const char* _CheckCompression(
|
||||||
|
const SectionInfo& section) const;
|
||||||
|
|
||||||
|
status_t _ParseTOCAttributeTypes();
|
||||||
|
|
||||||
|
status_t _ParseStrings();
|
||||||
|
|
||||||
|
status_t _ParseContent(AttributeHandlerContext* context,
|
||||||
|
AttributeHandler* rootAttributeHandler);
|
||||||
|
status_t _ParseAttributeTree(
|
||||||
|
AttributeHandlerContext* context);
|
||||||
|
|
||||||
|
status_t _ParsePackageAttributes(
|
||||||
|
AttributeHandlerContext* context);
|
||||||
|
status_t _ParsePackageVersion(
|
||||||
|
BPackageVersionData& _version,
|
||||||
|
const char* major = NULL);
|
||||||
|
status_t _ParsePackageProvides(
|
||||||
|
BPackageResolvableData& _resolvable,
|
||||||
|
BPackageResolvableType providesType);
|
||||||
|
status_t _ParsePackageResolvableExpression(
|
||||||
|
BPackageResolvableExpressionData&
|
||||||
|
_resolvableExpression,
|
||||||
|
const char* resolvableName,
|
||||||
|
bool hasChildren);
|
||||||
|
|
||||||
|
status_t _ReadPackageAttribute(uint8& _id,
|
||||||
|
AttributeValue& _value,
|
||||||
|
bool* _hasChildren = NULL,
|
||||||
|
uint64* _tag = NULL);
|
||||||
|
|
||||||
|
status_t _ReadAttributeValue(uint8 type, uint8 encoding,
|
||||||
|
AttributeValue& _value);
|
||||||
|
|
||||||
|
status_t _ReadUnsignedLEB128(uint64& _value);
|
||||||
|
status_t _ReadString(const char*& _string,
|
||||||
|
size_t* _stringLength = NULL);
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
inline status_t _Read(Type& _value);
|
||||||
|
|
||||||
|
status_t _GetTOCBuffer(size_t size,
|
||||||
|
const void*& _buffer);
|
||||||
|
status_t _ReadSectionBuffer(void* buffer, size_t size);
|
||||||
|
|
||||||
|
status_t _ReadBuffer(off_t offset, void* buffer,
|
||||||
|
size_t size);
|
||||||
|
status_t _ReadCompressedBuffer(
|
||||||
|
const SectionInfo& section);
|
||||||
|
|
||||||
|
static int8 _GetStandardIndex(const AttributeType* type);
|
||||||
|
|
||||||
|
inline AttributeHandler* _CurrentAttributeHandler() const;
|
||||||
|
inline void _PushAttributeHandler(
|
||||||
|
AttributeHandler* handler);
|
||||||
|
inline AttributeHandler* _PopAttributeHandler();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BErrorOutput* fErrorOutput;
|
||||||
|
int fFD;
|
||||||
|
bool fOwnsFD;
|
||||||
|
|
||||||
|
uint64 fTotalSize;
|
||||||
|
uint64 fHeapOffset;
|
||||||
|
uint64 fHeapSize;
|
||||||
|
|
||||||
|
uint64 fTOCAttributeTypesLength;
|
||||||
|
uint64 fTOCAttributeTypesCount;
|
||||||
|
|
||||||
|
SectionInfo fTOCSection;
|
||||||
|
SectionInfo fPackageAttributesSection;
|
||||||
|
SectionInfo* fCurrentSection;
|
||||||
|
|
||||||
|
AttributeTypeReference* fAttributeTypes;
|
||||||
|
|
||||||
|
AttributeHandlerList* fAttributeHandlerStack;
|
||||||
|
|
||||||
|
uint8* fScratchBuffer;
|
||||||
|
size_t fScratchBufferSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
status_t
|
||||||
|
PackageReaderImpl::_Read(Type& _value)
|
||||||
|
{
|
||||||
|
return _ReadSectionBuffer(&_value, sizeof(Type));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
} // namespace BHPKG
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__HPKG__PRIVATE__REPOSITORY_READER_IMPL_H_
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <util/DoublyLinkedList.h>
|
#include <util/DoublyLinkedList.h>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
|
|
||||||
#include <package/hpkg/DataOutput.h>
|
#include <package/hpkg/DataOutput.h>
|
||||||
#include <package/hpkg/Strings.h>
|
#include <package/hpkg/Strings.h>
|
||||||
@@ -79,10 +79,10 @@ protected:
|
|||||||
struct PackageAttribute :
|
struct PackageAttribute :
|
||||||
public DoublyLinkedListLinkImpl<PackageAttribute>,
|
public DoublyLinkedListLinkImpl<PackageAttribute>,
|
||||||
public AttributeValue {
|
public AttributeValue {
|
||||||
HPKGPackageAttributeID id;
|
BHPKGAttributeID id;
|
||||||
DoublyLinkedList<PackageAttribute> children;
|
DoublyLinkedList<PackageAttribute> children;
|
||||||
|
|
||||||
PackageAttribute(HPKGPackageAttributeID id_, uint8 type,
|
PackageAttribute(BHPKGAttributeID id_, uint8 type,
|
||||||
uint8 encoding);
|
uint8 encoding);
|
||||||
~PackageAttribute();
|
~PackageAttribute();
|
||||||
|
|
||||||
|
|||||||
@@ -1,165 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
|
||||||
#define _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
|
||||||
|
|
||||||
#include <package/hpkg/HPKGDefs.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
|
||||||
|
|
||||||
namespace BHPKG {
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
|
|
||||||
|
|
||||||
// header
|
|
||||||
struct hpkg_header {
|
|
||||||
uint32 magic; // "hpkg"
|
|
||||||
uint16 header_size;
|
|
||||||
uint16 version;
|
|
||||||
uint64 total_size;
|
|
||||||
|
|
||||||
// package attributes section
|
|
||||||
uint32 attributes_compression;
|
|
||||||
uint32 attributes_length_compressed;
|
|
||||||
uint32 attributes_length_uncompressed;
|
|
||||||
uint32 attributes_strings_length;
|
|
||||||
uint32 attributes_strings_count;
|
|
||||||
|
|
||||||
// TOC section
|
|
||||||
uint32 toc_compression;
|
|
||||||
uint64 toc_length_compressed;
|
|
||||||
uint64 toc_length_uncompressed;
|
|
||||||
|
|
||||||
uint64 toc_attribute_types_length;
|
|
||||||
uint64 toc_attribute_types_count;
|
|
||||||
uint64 toc_strings_length;
|
|
||||||
uint64 toc_strings_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// header
|
|
||||||
struct hpkg_repo_header {
|
|
||||||
uint32 magic; // "hpkr"
|
|
||||||
uint16 header_size;
|
|
||||||
uint16 version;
|
|
||||||
uint32 total_size;
|
|
||||||
|
|
||||||
// repository info section
|
|
||||||
uint32 info_compression;
|
|
||||||
uint32 info_length_compressed;
|
|
||||||
uint32 info_length_uncompressed;
|
|
||||||
|
|
||||||
// package attributes section
|
|
||||||
uint32 packages_compression;
|
|
||||||
uint32 packages_length_compressed;
|
|
||||||
uint32 packages_length_uncompressed;
|
|
||||||
uint32 packages_strings_length;
|
|
||||||
uint32 packages_strings_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// attribute tag arithmetics
|
|
||||||
#define HPKG_ATTRIBUTE_TAG_COMPOSE(index, encoding, hasChildren) \
|
|
||||||
(((uint64(index) << 3) | uint64(encoding) << 1 \
|
|
||||||
| ((hasChildren) ? 1 : 0)) + 1)
|
|
||||||
#define HPKG_ATTRIBUTE_TAG_INDEX(tag) (uint64((tag) - 1) >> 3)
|
|
||||||
#define HPKG_ATTRIBUTE_TAG_ENCODING(tag) ((uint64((tag) - 1) >> 1) & 0x3)
|
|
||||||
#define HPKG_ATTRIBUTE_TAG_HAS_CHILDREN(tag) ((uint64((tag) - 1) & 0x1) != 0)
|
|
||||||
|
|
||||||
// package attribute tag arithmetics
|
|
||||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_COMPOSE(id, type, encoding, hasChildren) \
|
|
||||||
(((uint16(encoding) << 9) | (((hasChildren) ? 1 : 0) << 8) \
|
|
||||||
| (uint16(type) << 5) | (uint16(id))) + 1)
|
|
||||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_ENCODING(tag) \
|
|
||||||
((uint16((tag) - 1) >> 9) & 0x3)
|
|
||||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_HAS_CHILDREN(tag) \
|
|
||||||
(((uint16((tag) - 1) >> 8) & 0x1) != 0)
|
|
||||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_TYPE(tag) \
|
|
||||||
((uint16((tag) - 1) >> 5) & 0x7)
|
|
||||||
#define HPKG_PACKAGE_ATTRIBUTE_TAG_ID(tag) \
|
|
||||||
(uint16((tag) - 1) & 0x1f)
|
|
||||||
|
|
||||||
|
|
||||||
// standard attribute names
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY "dir:entry"
|
|
||||||
// path/entry name (string)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_TYPE "file:type"
|
|
||||||
// file type (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS "file:permissions"
|
|
||||||
// file permissions (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_USER "file:user"
|
|
||||||
// file user (string)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_GROUP "file:group"
|
|
||||||
// file group (string)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATIME "file:atime"
|
|
||||||
// file access time in seconds (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_MTIME "file:mtime"
|
|
||||||
// file modification time in seconds (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_CRTIME "file:crtime"
|
|
||||||
// file creation time in seconds (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATIME_NANOS "file:atime:nanos"
|
|
||||||
// file access time nanoseconds fraction (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_MTIME_NANOS "file:mtime:nanos"
|
|
||||||
// file modification time nanoseconds fraction (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_CRTIM_NANOS "file:crtime:nanos"
|
|
||||||
// file creation time nanoseconds fraction (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE "file:attribute"
|
|
||||||
// file attribute (string)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE "file:attribute:type"
|
|
||||||
// file attribute type (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_DATA "data"
|
|
||||||
// (file/attribute) data (raw)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_DATA_COMPRESSION "data:compression"
|
|
||||||
// (file/attribute) data compression (uint, default: none)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_DATA_SIZE "data:size"
|
|
||||||
// (file/attribute) uncompressed data size (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_DATA_CHUNK_SIZE "data:chunk_size"
|
|
||||||
// the size of compressed (file/attribute) data chunks (uint)
|
|
||||||
#define HPKG_ATTRIBUTE_NAME_SYMLINK_PATH "symlink:path"
|
|
||||||
// symlink path (string)
|
|
||||||
|
|
||||||
|
|
||||||
// package attribute IDs
|
|
||||||
enum HPKGPackageAttributeID {
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_NAME = 0,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_SUMMARY,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_DESCRIPTION,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VENDOR,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PACKAGER,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_FLAGS,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_ARCHITECTURE,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MAJOR,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MINOR,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MICRO,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_RELEASE,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_COPYRIGHT,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_LICENSE,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES_TYPE,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_REQUIRES,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_SUPPLEMENTS,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_CONFLICTS,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_FRESHENS,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_REPLACES,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_CHECKSUM,
|
|
||||||
//
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_ENUM_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
} // namespace BHPKG
|
|
||||||
|
|
||||||
} // namespace BPackageKit
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
|
|
||||||
|
|
||||||
static const uint32 kMaxCachedBuffers = 32;
|
static const uint32 kMaxCachedBuffers = 32;
|
||||||
|
|||||||
@@ -264,12 +264,6 @@ struct Volume::PackageLoaderContentHandler : BPackageContentHandler {
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandlePackageAttributesDone()
|
|
||||||
{
|
|
||||||
// TODO!
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void HandleErrorOccurred()
|
virtual void HandleErrorOccurred()
|
||||||
{
|
{
|
||||||
fErrorOccurred = true;
|
fErrorOccurred = true;
|
||||||
|
|||||||
@@ -46,16 +46,13 @@ public:
|
|||||||
printf("\t%s\n", path);
|
printf("\t%s\n", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnTOCSizeInfo(uint64 uncompressedAttributeTypesSize,
|
virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
|
||||||
uint64 uncompressedStringsSize, uint64 uncompressedMainSize,
|
uint64 uncompressedMainSize, uint64 uncompressedTOCSize)
|
||||||
uint64 uncompressedTOCSize)
|
|
||||||
{
|
{
|
||||||
if (fQuiet || !fVerbose)
|
if (fQuiet || !fVerbose)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("----- TOC Info -----------------------------------\n");
|
printf("----- TOC Info -----------------------------------\n");
|
||||||
printf("attribute types size: %10llu (uncompressed)\n",
|
|
||||||
uncompressedAttributeTypesSize);
|
|
||||||
printf("cached strings size: %10llu (uncompressed)\n",
|
printf("cached strings size: %10llu (uncompressed)\n",
|
||||||
uncompressedStringsSize);
|
uncompressedStringsSize);
|
||||||
printf("TOC main size: %10llu (uncompressed)\n",
|
printf("TOC main size: %10llu (uncompressed)\n",
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandleAttribute(const char* attributeName,
|
virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
|
||||||
const BPackageAttributeValue& value, void* parentToken, void*& _token)
|
const BPackageAttributeValue& value, void* parentToken, void*& _token)
|
||||||
{
|
{
|
||||||
if (fErrorOccurred)
|
if (fErrorOccurred)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
printf("%*s>%s: ", fLevel * 2, "", attributeName);
|
printf("%*s>%s: ", fLevel * 2, "", AttributeNameForID(attributeID));
|
||||||
_PrintValue(value);
|
_PrintValue(value);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
virtual status_t HandleAttributeDone(BHPKGAttributeID attributeID,
|
||||||
const BPackageAttributeValue& value, void* token)
|
const BPackageAttributeValue& value, void* token)
|
||||||
{
|
{
|
||||||
if (fErrorOccurred)
|
if (fErrorOccurred)
|
||||||
@@ -58,7 +58,7 @@ struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
|
|||||||
fLevel--;
|
fLevel--;
|
||||||
|
|
||||||
if (fHasChildren)
|
if (fHasChildren)
|
||||||
printf("%*s<%s\n", fLevel * 2, "", attributeName);
|
printf("%*s<%s\n", fLevel * 2, "", AttributeNameForID(attributeID));
|
||||||
|
|
||||||
fHasChildren = true;
|
fHasChildren = true;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -144,14 +144,12 @@ command_dump(int argc, const char* const* argv)
|
|||||||
StandardErrorOutput errorOutput;
|
StandardErrorOutput errorOutput;
|
||||||
BPackageReader packageReader(&errorOutput);
|
BPackageReader packageReader(&errorOutput);
|
||||||
status_t error = packageReader.Init(packageFileName);
|
status_t error = packageReader.Init(packageFileName);
|
||||||
printf("Init(): %s\n", strerror(error));
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// list
|
// list
|
||||||
PackageContentDumpHandler handler;
|
PackageContentDumpHandler handler;
|
||||||
error = packageReader.ParseContent(&handler);
|
error = packageReader.ParseContent(&handler);
|
||||||
printf("ParseContent(): %s\n", strerror(error));
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -229,11 +229,6 @@ struct PackageContentExtractHandler : BPackageContentHandler {
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandlePackageAttributesDone()
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void HandleErrorOccurred()
|
virtual void HandleErrorOccurred()
|
||||||
{
|
{
|
||||||
fErrorOccurred = true;
|
fErrorOccurred = true;
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ struct PackageContentListHandler : BPackageContentHandler {
|
|||||||
virtual status_t HandlePackageAttribute(
|
virtual status_t HandlePackageAttribute(
|
||||||
const BPackageInfoAttributeValue& value)
|
const BPackageInfoAttributeValue& value)
|
||||||
{
|
{
|
||||||
switch (value.attributeIndex) {
|
switch (value.attributeID) {
|
||||||
case B_PACKAGE_INFO_NAME:
|
case B_PACKAGE_INFO_NAME:
|
||||||
printf("package-attributes:\n");
|
printf("package-attributes:\n");
|
||||||
printf("\tname: %s\n", value.string);
|
printf("\tname: %s\n", value.string);
|
||||||
@@ -218,19 +218,13 @@ struct PackageContentListHandler : BPackageContentHandler {
|
|||||||
default:
|
default:
|
||||||
printf(
|
printf(
|
||||||
"*** Invalid package attribute section: unexpected "
|
"*** Invalid package attribute section: unexpected "
|
||||||
"package attribute index %d encountered\n",
|
"package attribute id %d encountered\n", value.attributeID);
|
||||||
value.attributeIndex);
|
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandlePackageAttributesDone()
|
|
||||||
{
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void HandleErrorOccurred()
|
virtual void HandleErrorOccurred()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -308,14 +302,12 @@ command_list(int argc, const char* const* argv)
|
|||||||
StandardErrorOutput errorOutput;
|
StandardErrorOutput errorOutput;
|
||||||
BPackageReader packageReader(&errorOutput);
|
BPackageReader packageReader(&errorOutput);
|
||||||
status_t error = packageReader.Init(packageFileName);
|
status_t error = packageReader.Init(packageFileName);
|
||||||
printf("Init(): %s\n", strerror(error));
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// list
|
// list
|
||||||
PackageContentListHandler handler(listAttributes);
|
PackageContentListHandler handler(listAttributes);
|
||||||
error = packageReader.ParseContent(&handler);
|
error = packageReader.ParseContent(&handler);
|
||||||
printf("ParseContent(): %s\n", strerror(error));
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
using namespace BPackageKit::BHPKG;
|
using namespace BPackageKit::BHPKG;
|
||||||
using namespace BPackageKit;
|
using namespace BPackageKit;
|
||||||
|
|
||||||
|
/*
|
||||||
struct PackageContentListHandler : BPackageContentHandler {
|
struct PackageContentListHandler : BPackageContentHandler {
|
||||||
PackageContentListHandler(bool listAttributes)
|
PackageContentListHandler(bool listAttributes)
|
||||||
:
|
:
|
||||||
@@ -265,7 +265,7 @@ private:
|
|||||||
int fLevel;
|
int fLevel;
|
||||||
bool fListAttribute;
|
bool fListAttribute;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
command_list(int argc, const char* const* argv)
|
command_list(int argc, const char* const* argv)
|
||||||
@@ -305,19 +305,17 @@ command_list(int argc, const char* const* argv)
|
|||||||
const char* packageFileName = argv[optind++];
|
const char* packageFileName = argv[optind++];
|
||||||
|
|
||||||
// open package
|
// open package
|
||||||
StandardErrorOutput errorOutput;
|
// StandardErrorOutput errorOutput;
|
||||||
BPackageReader packageReader(&errorOutput);
|
// BPackageReader packageReader(&errorOutput);
|
||||||
status_t error = packageReader.Init(packageFileName);
|
// status_t error = packageReader.Init(packageFileName);
|
||||||
printf("Init(): %s\n", strerror(error));
|
// if (error != B_OK)
|
||||||
if (error != B_OK)
|
// return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
// list
|
// list
|
||||||
PackageContentListHandler handler(listAttributes);
|
// PackageContentListHandler handler(listAttributes);
|
||||||
error = packageReader.ParseContent(&handler);
|
// error = packageReader.ParseContent(&handler);
|
||||||
printf("ParseContent(): %s\n", strerror(error));
|
// if (error != B_OK)
|
||||||
if (error != B_OK)
|
// return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace BPackageKit {
|
|||||||
|
|
||||||
|
|
||||||
BPackageVersion::BPackageVersion()
|
BPackageVersion::BPackageVersion()
|
||||||
|
:
|
||||||
|
fRelease(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,66 @@ namespace BHPKG {
|
|||||||
// #pragma mark - BLowLevelPackageContentHandler
|
// #pragma mark - BLowLevelPackageContentHandler
|
||||||
|
|
||||||
|
|
||||||
|
static const char* kAttributeNames[B_HPKG_ATTRIBUTE_ID_ENUM_COUNT + 1] = {
|
||||||
|
"dir:entry",
|
||||||
|
"file:type",
|
||||||
|
"file:permissions",
|
||||||
|
"file:user",
|
||||||
|
"file:group",
|
||||||
|
"file:atime",
|
||||||
|
"file:mtime",
|
||||||
|
"file:crtime",
|
||||||
|
"file:atime:nanos",
|
||||||
|
"file:mtime:nanos",
|
||||||
|
"file:crtime:nanos",
|
||||||
|
"file:attribute",
|
||||||
|
"file:attribute:type",
|
||||||
|
"data",
|
||||||
|
"data:compression",
|
||||||
|
"data:size",
|
||||||
|
"data:chunk_size",
|
||||||
|
"symlink:path",
|
||||||
|
"package:name",
|
||||||
|
"package:summary",
|
||||||
|
"package:description",
|
||||||
|
"package:vendor",
|
||||||
|
"package:packager",
|
||||||
|
"package:flags",
|
||||||
|
"package:architecture",
|
||||||
|
"package:version.major",
|
||||||
|
"package:version.minor",
|
||||||
|
"package:version.micro",
|
||||||
|
"package:version.release",
|
||||||
|
"package:copyright",
|
||||||
|
"package:license",
|
||||||
|
"package:provides",
|
||||||
|
"package:provides.type",
|
||||||
|
"package:requires",
|
||||||
|
"package:supplements",
|
||||||
|
"package:conflicts",
|
||||||
|
"package:freshens",
|
||||||
|
"package:replaces",
|
||||||
|
"package:resolvable.operator",
|
||||||
|
"package:checksum",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
BLowLevelPackageContentHandler::~BLowLevelPackageContentHandler()
|
BLowLevelPackageContentHandler::~BLowLevelPackageContentHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ const char*
|
||||||
|
BLowLevelPackageContentHandler::AttributeNameForID(uint8 id)
|
||||||
|
{
|
||||||
|
if (id >= B_HPKG_ATTRIBUTE_ID_ENUM_COUNT)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return kAttributeNames[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - BPackageContentHandler
|
// #pragma mark - BPackageContentHandler
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
#include <package/hpkg/BufferCache.h>
|
#include <package/hpkg/BufferCache.h>
|
||||||
#include <package/hpkg/CachedBuffer.h>
|
#include <package/hpkg/CachedBuffer.h>
|
||||||
#include <package/hpkg/DataOutput.h>
|
#include <package/hpkg/DataOutput.h>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
|
|
||||||
#include <package/hpkg/DataOutput.h>
|
#include <package/hpkg/DataOutput.h>
|
||||||
#include <package/hpkg/DataReader.h>
|
#include <package/hpkg/DataReader.h>
|
||||||
@@ -52,87 +52,15 @@ static const size_t kZlibCompressionSizeThreshold = 64;
|
|||||||
// #pragma mark - Attributes
|
// #pragma mark - Attributes
|
||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::AttributeTypeKey {
|
|
||||||
const char* name;
|
|
||||||
uint8 type;
|
|
||||||
|
|
||||||
AttributeTypeKey(const char* name, uint8 type)
|
|
||||||
:
|
|
||||||
name(name),
|
|
||||||
type(type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::AttributeType {
|
|
||||||
char* name;
|
|
||||||
uint8 type;
|
|
||||||
int32 index;
|
|
||||||
uint32 usageCount;
|
|
||||||
AttributeType* next; // hash table link
|
|
||||||
|
|
||||||
AttributeType()
|
|
||||||
:
|
|
||||||
name(NULL),
|
|
||||||
type(B_HPKG_ATTRIBUTE_TYPE_INVALID),
|
|
||||||
index(-1),
|
|
||||||
usageCount(1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~AttributeType()
|
|
||||||
{
|
|
||||||
free(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Init(const char* name, uint8 type)
|
|
||||||
{
|
|
||||||
this->name = strdup(name);
|
|
||||||
if (this->name == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->type = type;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::AttributeTypeHashDefinition {
|
|
||||||
typedef AttributeTypeKey KeyType;
|
|
||||||
typedef AttributeType ValueType;
|
|
||||||
|
|
||||||
size_t HashKey(const AttributeTypeKey& key) const
|
|
||||||
{
|
|
||||||
return hash_string(key.name) ^ (uint32)key.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Hash(const AttributeType* value) const
|
|
||||||
{
|
|
||||||
return hash_string(value->name) ^ (uint32)value->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Compare(const AttributeTypeKey& key, const AttributeType* value) const
|
|
||||||
{
|
|
||||||
return strcmp(value->name, key.name) == 0 && value->type == key.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
AttributeType*& GetLink(AttributeType* value) const
|
|
||||||
{
|
|
||||||
return value->next;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::Attribute
|
struct PackageWriterImpl::Attribute
|
||||||
: public DoublyLinkedListLinkImpl<Attribute> {
|
: public DoublyLinkedListLinkImpl<Attribute> {
|
||||||
AttributeType* type;
|
BHPKGAttributeID id;
|
||||||
AttributeValue value;
|
AttributeValue value;
|
||||||
DoublyLinkedList<Attribute> children;
|
DoublyLinkedList<Attribute> children;
|
||||||
|
|
||||||
Attribute(AttributeType* type)
|
Attribute(BHPKGAttributeID id_ = B_HPKG_ATTRIBUTE_ID_ENUM_COUNT)
|
||||||
:
|
:
|
||||||
type(type)
|
id(id_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,14 +82,6 @@ struct PackageWriterImpl::Attribute
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct PackageWriterImpl::AttributeTypeUsageGreater {
|
|
||||||
bool operator()(const AttributeType* a, const AttributeType* b)
|
|
||||||
{
|
|
||||||
return a->usageCount > b->usageCount;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - Entry
|
// #pragma mark - Entry
|
||||||
|
|
||||||
|
|
||||||
@@ -279,11 +199,11 @@ private:
|
|||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
inline PackageWriterImpl::Attribute*
|
inline PackageWriterImpl::Attribute*
|
||||||
PackageWriterImpl::_AddAttribute(const char* attributeName, Type value)
|
PackageWriterImpl::_AddAttribute(BHPKGAttributeID attributeID, Type value)
|
||||||
{
|
{
|
||||||
AttributeValue attributeValue;
|
AttributeValue attributeValue;
|
||||||
attributeValue.SetTo(value);
|
attributeValue.SetTo(value);
|
||||||
return _AddAttribute(attributeName, attributeValue);
|
return _AddAttribute(attributeID, attributeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -298,8 +218,7 @@ PackageWriterImpl::PackageWriterImpl(BPackageWriterListener* listener)
|
|||||||
fDataBufferSize(2 * B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB),
|
fDataBufferSize(2 * B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB),
|
||||||
fRootEntry(NULL),
|
fRootEntry(NULL),
|
||||||
fRootAttribute(NULL),
|
fRootAttribute(NULL),
|
||||||
fTopAttribute(NULL),
|
fTopAttribute(NULL)
|
||||||
fAttributeTypes(NULL)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,15 +227,6 @@ PackageWriterImpl::~PackageWriterImpl()
|
|||||||
{
|
{
|
||||||
delete fRootAttribute;
|
delete fRootAttribute;
|
||||||
|
|
||||||
if (fAttributeTypes != NULL) {
|
|
||||||
AttributeType* attributeType = fAttributeTypes->Clear(true);
|
|
||||||
while (attributeType != NULL) {
|
|
||||||
AttributeType* next = attributeType->next;
|
|
||||||
delete attributeType;
|
|
||||||
attributeType = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete fRootEntry;
|
delete fRootEntry;
|
||||||
|
|
||||||
free(fDataBuffer);
|
free(fDataBuffer);
|
||||||
@@ -409,14 +319,10 @@ PackageWriterImpl::_Init(const char* fileName)
|
|||||||
if (fStringCache.Init() != B_OK)
|
if (fStringCache.Init() != B_OK)
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
|
|
||||||
fAttributeTypes = new AttributeTypeTable;
|
|
||||||
if (fAttributeTypes->Init() != B_OK)
|
|
||||||
throw std::bad_alloc();
|
|
||||||
|
|
||||||
// create entry list
|
// create entry list
|
||||||
fRootEntry = new Entry(NULL, 0, true);
|
fRootEntry = new Entry(NULL, 0, true);
|
||||||
|
|
||||||
fRootAttribute = new Attribute(NULL);
|
fRootAttribute = new Attribute();
|
||||||
|
|
||||||
fHeapOffset = fHeapEnd = sizeof(hpkg_header);
|
fHeapOffset = fHeapEnd = sizeof(hpkg_header);
|
||||||
fTopAttribute = fRootAttribute;
|
fTopAttribute = fRootAttribute;
|
||||||
@@ -587,12 +493,10 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
|||||||
zlibWriter.Init();
|
zlibWriter.Init();
|
||||||
|
|
||||||
// write the sections
|
// write the sections
|
||||||
uint64 uncompressedAttributeTypesSize;
|
|
||||||
uint64 uncompressedStringsSize;
|
uint64 uncompressedStringsSize;
|
||||||
uint64 uncompressedMainSize;
|
uint64 uncompressedMainSize;
|
||||||
int32 cachedStringsWritten = _WriteTOCSections(
|
int32 cachedStringsWritten
|
||||||
uncompressedAttributeTypesSize, uncompressedStringsSize,
|
= _WriteTOCSections(uncompressedStringsSize, uncompressedMainSize);
|
||||||
uncompressedMainSize);
|
|
||||||
|
|
||||||
// finish the writer
|
// finish the writer
|
||||||
zlibWriter.Finish();
|
zlibWriter.Finish();
|
||||||
@@ -601,8 +505,7 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
|||||||
|
|
||||||
off_t endOffset = fHeapEnd;
|
off_t endOffset = fHeapEnd;
|
||||||
|
|
||||||
fListener->OnTOCSizeInfo(uncompressedAttributeTypesSize,
|
fListener->OnTOCSizeInfo(uncompressedStringsSize, uncompressedMainSize,
|
||||||
uncompressedStringsSize, uncompressedMainSize,
|
|
||||||
zlibWriter.BytesWritten());
|
zlibWriter.BytesWritten());
|
||||||
|
|
||||||
// update the header
|
// update the header
|
||||||
@@ -615,10 +518,6 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
|||||||
zlibWriter.BytesWritten());
|
zlibWriter.BytesWritten());
|
||||||
|
|
||||||
// TOC subsections
|
// TOC subsections
|
||||||
header.toc_attribute_types_length = B_HOST_TO_BENDIAN_INT64(
|
|
||||||
uncompressedAttributeTypesSize);
|
|
||||||
header.toc_attribute_types_count = B_HOST_TO_BENDIAN_INT64(
|
|
||||||
fAttributeTypes->CountElements());
|
|
||||||
header.toc_strings_length = B_HOST_TO_BENDIAN_INT64(
|
header.toc_strings_length = B_HOST_TO_BENDIAN_INT64(
|
||||||
uncompressedStringsSize);
|
uncompressedStringsSize);
|
||||||
header.toc_strings_count = B_HOST_TO_BENDIAN_INT64(cachedStringsWritten);
|
header.toc_strings_count = B_HOST_TO_BENDIAN_INT64(cachedStringsWritten);
|
||||||
@@ -626,13 +525,8 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
|||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
PackageWriterImpl::_WriteTOCSections(uint64& _attributeTypesSize,
|
PackageWriterImpl::_WriteTOCSections(uint64& _stringsSize, uint64& _mainSize)
|
||||||
uint64& _stringsSize, uint64& _mainSize)
|
|
||||||
{
|
{
|
||||||
// write the attribute type abbreviations
|
|
||||||
uint64 attributeTypesOffset = DataWriter()->BytesWritten();
|
|
||||||
_WriteAttributeTypes();
|
|
||||||
|
|
||||||
// write the cached strings
|
// write the cached strings
|
||||||
uint64 cachedStringsOffset = DataWriter()->BytesWritten();
|
uint64 cachedStringsOffset = DataWriter()->BytesWritten();
|
||||||
int32 cachedStringsWritten = WriteCachedStrings(fStringCache, 2);
|
int32 cachedStringsWritten = WriteCachedStrings(fStringCache, 2);
|
||||||
@@ -641,7 +535,6 @@ PackageWriterImpl::_WriteTOCSections(uint64& _attributeTypesSize,
|
|||||||
uint64 mainOffset = DataWriter()->BytesWritten();
|
uint64 mainOffset = DataWriter()->BytesWritten();
|
||||||
_WriteAttributeChildren(fRootAttribute);
|
_WriteAttributeChildren(fRootAttribute);
|
||||||
|
|
||||||
_attributeTypesSize = cachedStringsOffset - attributeTypesOffset;
|
|
||||||
_stringsSize = mainOffset - cachedStringsOffset;
|
_stringsSize = mainOffset - cachedStringsOffset;
|
||||||
_mainSize = DataWriter()->BytesWritten() - mainOffset;
|
_mainSize = DataWriter()->BytesWritten() - mainOffset;
|
||||||
|
|
||||||
@@ -649,50 +542,16 @@ PackageWriterImpl::_WriteTOCSections(uint64& _attributeTypesSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PackageWriterImpl::_WriteAttributeTypes()
|
|
||||||
{
|
|
||||||
// create an array of the attribute types
|
|
||||||
int32 attributeTypeCount = fAttributeTypes->CountElements();
|
|
||||||
AttributeType** attributeTypes = new AttributeType*[attributeTypeCount];
|
|
||||||
ArrayDeleter<AttributeType*> attributeTypesDeleter(attributeTypes);
|
|
||||||
|
|
||||||
int32 index = 0;
|
|
||||||
for (AttributeTypeTable::Iterator it = fAttributeTypes->GetIterator();
|
|
||||||
AttributeType* type = it.Next();) {
|
|
||||||
attributeTypes[index++] = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort it by descending usage count
|
|
||||||
std::sort(attributeTypes, attributeTypes + attributeTypeCount,
|
|
||||||
AttributeTypeUsageGreater());
|
|
||||||
|
|
||||||
// assign the indices and write entries to disk
|
|
||||||
for (int32 i = 0; i < attributeTypeCount; i++) {
|
|
||||||
AttributeType* attributeType = attributeTypes[i];
|
|
||||||
attributeType->index = i;
|
|
||||||
|
|
||||||
Write<uint8>(attributeType->type);
|
|
||||||
WriteString(attributeType->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write a terminating 0 byte
|
|
||||||
Write<uint8>(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageWriterImpl::_WriteAttributeChildren(Attribute* attribute)
|
PackageWriterImpl::_WriteAttributeChildren(Attribute* attribute)
|
||||||
{
|
{
|
||||||
DoublyLinkedList<Attribute>::Iterator it
|
DoublyLinkedList<Attribute>::Iterator it
|
||||||
= attribute->children.GetIterator();
|
= attribute->children.GetIterator();
|
||||||
while (Attribute* child = it.Next()) {
|
while (Attribute* child = it.Next()) {
|
||||||
AttributeType* type = child->type;
|
|
||||||
|
|
||||||
// write tag
|
// write tag
|
||||||
uint8 encoding = child->value.ApplicableEncoding();
|
uint8 encoding = child->value.ApplicableEncoding();
|
||||||
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(type->index,
|
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(child->id,
|
||||||
encoding, !child->children.IsEmpty()));
|
child->value.type, encoding, !child->children.IsEmpty()));
|
||||||
|
|
||||||
// write value
|
// write value
|
||||||
WriteAttributeValue(child->value, encoding);
|
WriteAttributeValue(child->value, encoding);
|
||||||
@@ -800,19 +659,19 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
|||||||
|
|
||||||
// add attribute entry
|
// add attribute entry
|
||||||
Attribute* entryAttribute = _AddStringAttribute(
|
Attribute* entryAttribute = _AddStringAttribute(
|
||||||
HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY, fileName);
|
B_HPKG_ATTRIBUTE_ID_DIRECTORY_ENTRY, fileName);
|
||||||
Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute);
|
Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute);
|
||||||
|
|
||||||
// add stat data
|
// add stat data
|
||||||
if (fileType != B_HPKG_DEFAULT_FILE_TYPE)
|
if (fileType != B_HPKG_DEFAULT_FILE_TYPE)
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_TYPE, fileType);
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_TYPE, fileType);
|
||||||
if (defaultPermissions != uint32(st.st_mode & ALLPERMS)) {
|
if (defaultPermissions != uint32(st.st_mode & ALLPERMS)) {
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS,
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_PERMISSIONS,
|
||||||
uint32(st.st_mode & ALLPERMS));
|
uint32(st.st_mode & ALLPERMS));
|
||||||
}
|
}
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_ATIME, uint32(st.st_atime));
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_ATIME, uint32(st.st_atime));
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_MTIME, uint32(st.st_mtime));
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_MTIME, uint32(st.st_mtime));
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_CRTIME, uint32(st.st_crtime));
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_CRTIME, uint32(st.st_crtime));
|
||||||
// TODO: File user/group!
|
// TODO: File user/group!
|
||||||
|
|
||||||
// add file data/symlink path
|
// add file data/symlink path
|
||||||
@@ -836,7 +695,7 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
path[bytesRead] = '\0';
|
path[bytesRead] = '\0';
|
||||||
_AddStringAttribute(HPKG_ATTRIBUTE_NAME_SYMLINK_PATH, path);
|
_AddStringAttribute(B_HPKG_ATTRIBUTE_ID_SYMLINK_PATH, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add attributes
|
// add attributes
|
||||||
@@ -854,12 +713,12 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
|||||||
|
|
||||||
// create attribute entry
|
// create attribute entry
|
||||||
Attribute* attributeAttribute = _AddStringAttribute(
|
Attribute* attributeAttribute = _AddStringAttribute(
|
||||||
HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE, entry->d_name);
|
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE, entry->d_name);
|
||||||
Stacker<Attribute> attributeAttributeStacker(fTopAttribute,
|
Stacker<Attribute> attributeAttributeStacker(fTopAttribute,
|
||||||
attributeAttribute);
|
attributeAttribute);
|
||||||
|
|
||||||
// add type
|
// add type
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE,
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE_TYPE,
|
||||||
(uint32)attrInfo.type);
|
(uint32)attrInfo.type);
|
||||||
|
|
||||||
// add data
|
// add data
|
||||||
@@ -912,11 +771,10 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
|||||||
|
|
||||||
|
|
||||||
PackageWriterImpl::Attribute*
|
PackageWriterImpl::Attribute*
|
||||||
PackageWriterImpl::_AddAttribute(const char* attributeName,
|
PackageWriterImpl::_AddAttribute(BHPKGAttributeID id,
|
||||||
const AttributeValue& value)
|
const AttributeValue& value)
|
||||||
{
|
{
|
||||||
Attribute* attribute = new Attribute(
|
Attribute* attribute = new Attribute(id);
|
||||||
_GetAttributeType(attributeName, value.type));
|
|
||||||
|
|
||||||
attribute->value = value;
|
attribute->value = value;
|
||||||
fTopAttribute->AddChild(attribute);
|
fTopAttribute->AddChild(attribute);
|
||||||
@@ -926,53 +784,32 @@ PackageWriterImpl::_AddAttribute(const char* attributeName,
|
|||||||
|
|
||||||
|
|
||||||
PackageWriterImpl::Attribute*
|
PackageWriterImpl::Attribute*
|
||||||
PackageWriterImpl::_AddStringAttribute(const char* attributeName,
|
PackageWriterImpl::_AddStringAttribute(BHPKGAttributeID attributeID,
|
||||||
const char* value)
|
const char* value)
|
||||||
{
|
{
|
||||||
AttributeValue attributeValue;
|
AttributeValue attributeValue;
|
||||||
attributeValue.SetTo(fStringCache.Get(value));
|
attributeValue.SetTo(fStringCache.Get(value));
|
||||||
return _AddAttribute(attributeName, attributeValue);
|
return _AddAttribute(attributeID, attributeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PackageWriterImpl::Attribute*
|
PackageWriterImpl::Attribute*
|
||||||
PackageWriterImpl::_AddDataAttribute(const char* attributeName, uint64 dataSize,
|
PackageWriterImpl::_AddDataAttribute(BHPKGAttributeID attributeID,
|
||||||
uint64 dataOffset)
|
uint64 dataSize, uint64 dataOffset)
|
||||||
{
|
{
|
||||||
AttributeValue attributeValue;
|
AttributeValue attributeValue;
|
||||||
attributeValue.SetToData(dataSize, dataOffset);
|
attributeValue.SetToData(dataSize, dataOffset);
|
||||||
return _AddAttribute(attributeName, attributeValue);
|
return _AddAttribute(attributeID, attributeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PackageWriterImpl::Attribute*
|
PackageWriterImpl::Attribute*
|
||||||
PackageWriterImpl::_AddDataAttribute(const char* attributeName, uint64 dataSize,
|
PackageWriterImpl::_AddDataAttribute(BHPKGAttributeID attributeID,
|
||||||
const uint8* data)
|
uint64 dataSize, const uint8* data)
|
||||||
{
|
{
|
||||||
AttributeValue attributeValue;
|
AttributeValue attributeValue;
|
||||||
attributeValue.SetToData(dataSize, data);
|
attributeValue.SetToData(dataSize, data);
|
||||||
return _AddAttribute(attributeName, attributeValue);
|
return _AddAttribute(attributeID, attributeValue);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PackageWriterImpl::AttributeType*
|
|
||||||
PackageWriterImpl::_GetAttributeType(const char* attributeName, uint8 type)
|
|
||||||
{
|
|
||||||
AttributeType* attributeType = fAttributeTypes->Lookup(
|
|
||||||
AttributeTypeKey(attributeName, type));
|
|
||||||
if (attributeType != NULL) {
|
|
||||||
attributeType->usageCount++;
|
|
||||||
return attributeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
attributeType = new AttributeType;
|
|
||||||
if (!attributeType->Init(attributeName, type)) {
|
|
||||||
delete attributeType;
|
|
||||||
throw std::bad_alloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
fAttributeTypes->Insert(attributeType);
|
|
||||||
return attributeType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -988,7 +825,7 @@ PackageWriterImpl::_AddData(BDataReader& dataReader, off_t size)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
_AddDataAttribute(HPKG_ATTRIBUTE_NAME_DATA, size, buffer);
|
_AddDataAttribute(B_HPKG_ATTRIBUTE_ID_DATA, size, buffer);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,14 +849,14 @@ PackageWriterImpl::_AddData(BDataReader& dataReader, off_t size)
|
|||||||
fHeapEnd = dataOffset + compressedSize;
|
fHeapEnd = dataOffset + compressedSize;
|
||||||
|
|
||||||
// add data attribute
|
// add data attribute
|
||||||
Attribute* dataAttribute = _AddDataAttribute(HPKG_ATTRIBUTE_NAME_DATA,
|
Attribute* dataAttribute = _AddDataAttribute(B_HPKG_ATTRIBUTE_ID_DATA,
|
||||||
compressedSize, dataOffset - fHeapOffset);
|
compressedSize, dataOffset - fHeapOffset);
|
||||||
Stacker<Attribute> attributeAttributeStacker(fTopAttribute, dataAttribute);
|
Stacker<Attribute> attributeAttributeStacker(fTopAttribute, dataAttribute);
|
||||||
|
|
||||||
// if compressed, add compression attributes
|
// if compressed, add compression attributes
|
||||||
if (compression != B_HPKG_COMPRESSION_NONE) {
|
if (compression != B_HPKG_COMPRESSION_NONE) {
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_DATA_COMPRESSION, compression);
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_DATA_COMPRESSION, compression);
|
||||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_DATA_SIZE, (uint64)size);
|
_AddAttribute(B_HPKG_ATTRIBUTE_ID_DATA_SIZE, (uint64)size);
|
||||||
// uncompressed size
|
// uncompressed size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <package/hpkg/RepositoryReader.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <package/hpkg/ErrorOutput.h>
|
||||||
|
#include <package/hpkg/RepositoryReaderImpl.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BHPKG {
|
||||||
|
|
||||||
|
|
||||||
|
BRepositoryReader::BRepositoryReader(BErrorOutput* errorOutput)
|
||||||
|
:
|
||||||
|
fImpl(new (std::nothrow) RepositoryReaderImpl(errorOutput))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRepositoryReader::~BRepositoryReader()
|
||||||
|
{
|
||||||
|
delete fImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryReader::Init(const char* fileName)
|
||||||
|
{
|
||||||
|
if (fImpl == NULL)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
return fImpl->Init(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BRepositoryReader::ParseContent(BRepositoryContentHandler* contentHandler)
|
||||||
|
{
|
||||||
|
if (fImpl == NULL)
|
||||||
|
return B_NO_INIT;
|
||||||
|
|
||||||
|
return fImpl->ParseContent(contentHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BHPKG
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||||
#include <package/hpkg/PackageReader.h>
|
#include <package/hpkg/PackageReader.h>
|
||||||
#include <package/ChecksumAccessors.h>
|
#include <package/ChecksumAccessors.h>
|
||||||
@@ -122,7 +122,7 @@ status_t
|
|||||||
RepositoryWriterImpl::HandlePackageAttribute(
|
RepositoryWriterImpl::HandlePackageAttribute(
|
||||||
const BPackageInfoAttributeValue& value)
|
const BPackageInfoAttributeValue& value)
|
||||||
{
|
{
|
||||||
switch (value.attributeIndex) {
|
switch (value.attributeID) {
|
||||||
case B_PACKAGE_INFO_NAME:
|
case B_PACKAGE_INFO_NAME:
|
||||||
fPackageInfo.SetName(value.string);
|
fPackageInfo.SetName(value.string);
|
||||||
break;
|
break;
|
||||||
@@ -191,7 +191,7 @@ RepositoryWriterImpl::HandlePackageAttribute(
|
|||||||
default:
|
default:
|
||||||
fListener->PrintError(
|
fListener->PrintError(
|
||||||
"Invalid package attribute section: unexpected package "
|
"Invalid package attribute section: unexpected package "
|
||||||
"attribute index %d encountered\n", value.attributeIndex);
|
"attribute id %d encountered\n", value.attributeID);
|
||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include <package/hpkg/haiku_package.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
|
|
||||||
#include <package/hpkg/DataReader.h>
|
#include <package/hpkg/DataReader.h>
|
||||||
#include <package/hpkg/ErrorOutput.h>
|
#include <package/hpkg/ErrorOutput.h>
|
||||||
@@ -276,7 +276,7 @@ WriterImplBase::ZlibDataWriter::WriteData(const void* buffer, size_t size)
|
|||||||
|
|
||||||
// #pragma mark - PackageAttribute
|
// #pragma mark - PackageAttribute
|
||||||
|
|
||||||
WriterImplBase::PackageAttribute::PackageAttribute(HPKGPackageAttributeID id_,
|
WriterImplBase::PackageAttribute::PackageAttribute(BHPKGAttributeID id_,
|
||||||
uint8 type_, uint8 encoding_)
|
uint8 type_, uint8 encoding_)
|
||||||
:
|
:
|
||||||
id(id_)
|
id(id_)
|
||||||
@@ -357,21 +357,22 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
const BPackageInfo& packageInfo)
|
const BPackageInfo& packageInfo)
|
||||||
{
|
{
|
||||||
// name
|
// name
|
||||||
PackageAttribute* name = new PackageAttribute(HPKG_PACKAGE_ATTRIBUTE_NAME,
|
PackageAttribute* name = new PackageAttribute(
|
||||||
B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_NAME, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
name->string = fPackageStringCache.Get(packageInfo.Name().String());
|
name->string = fPackageStringCache.Get(packageInfo.Name().String());
|
||||||
attributeList.Add(name);
|
attributeList.Add(name);
|
||||||
|
|
||||||
// summary
|
// summary
|
||||||
PackageAttribute* summary = new PackageAttribute(
|
PackageAttribute* summary = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_SUMMARY, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_SUMMARY, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
summary->string = fPackageStringCache.Get(packageInfo.Summary().String());
|
summary->string = fPackageStringCache.Get(packageInfo.Summary().String());
|
||||||
attributeList.Add(summary);
|
attributeList.Add(summary);
|
||||||
|
|
||||||
// description
|
// description
|
||||||
PackageAttribute* description = new PackageAttribute(
|
PackageAttribute* description = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_DESCRIPTION, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_DESCRIPTION, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
description->string
|
description->string
|
||||||
= fPackageStringCache.Get(packageInfo.Description().String());
|
= fPackageStringCache.Get(packageInfo.Description().String());
|
||||||
@@ -379,28 +380,28 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
|
|
||||||
// vendor
|
// vendor
|
||||||
PackageAttribute* vendor = new PackageAttribute(
|
PackageAttribute* vendor = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VENDOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VENDOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
vendor->string = fPackageStringCache.Get(packageInfo.Vendor().String());
|
vendor->string = fPackageStringCache.Get(packageInfo.Vendor().String());
|
||||||
attributeList.Add(vendor);
|
attributeList.Add(vendor);
|
||||||
|
|
||||||
// packager
|
// packager
|
||||||
PackageAttribute* packager = new PackageAttribute(
|
PackageAttribute* packager = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PACKAGER, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PACKAGER, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
packager->string = fPackageStringCache.Get(packageInfo.Packager().String());
|
packager->string = fPackageStringCache.Get(packageInfo.Packager().String());
|
||||||
attributeList.Add(packager);
|
attributeList.Add(packager);
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
PackageAttribute* flags = new PackageAttribute(
|
PackageAttribute* flags = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_FLAGS, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_FLAGS, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT);
|
B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT);
|
||||||
flags->unsignedInt = packageInfo.Flags();
|
flags->unsignedInt = packageInfo.Flags();
|
||||||
attributeList.Add(flags);
|
attributeList.Add(flags);
|
||||||
|
|
||||||
// architecture
|
// architecture
|
||||||
PackageAttribute* architecture = new PackageAttribute(
|
PackageAttribute* architecture = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_ARCHITECTURE, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_ARCHITECTURE, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||||
architecture->unsignedInt = packageInfo.Architecture();
|
architecture->unsignedInt = packageInfo.Architecture();
|
||||||
attributeList.Add(architecture);
|
attributeList.Add(architecture);
|
||||||
@@ -412,7 +413,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
const BObjectList<BString>& copyrightList = packageInfo.CopyrightList();
|
const BObjectList<BString>& copyrightList = packageInfo.CopyrightList();
|
||||||
for (int i = 0; i < copyrightList.CountItems(); ++i) {
|
for (int i = 0; i < copyrightList.CountItems(); ++i) {
|
||||||
PackageAttribute* copyright = new PackageAttribute(
|
PackageAttribute* copyright = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_COPYRIGHT, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_COPYRIGHT, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
copyright->string
|
copyright->string
|
||||||
= fPackageStringCache.Get(copyrightList.ItemAt(i)->String());
|
= fPackageStringCache.Get(copyrightList.ItemAt(i)->String());
|
||||||
@@ -423,7 +424,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
const BObjectList<BString>& licenseList = packageInfo.LicenseList();
|
const BObjectList<BString>& licenseList = packageInfo.LicenseList();
|
||||||
for (int i = 0; i < licenseList.CountItems(); ++i) {
|
for (int i = 0; i < licenseList.CountItems(); ++i) {
|
||||||
PackageAttribute* license = new PackageAttribute(
|
PackageAttribute* license = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_LICENSE, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_LICENSE, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
license->string
|
license->string
|
||||||
= fPackageStringCache.Get(licenseList.ItemAt(i)->String());
|
= fPackageStringCache.Get(licenseList.ItemAt(i)->String());
|
||||||
@@ -437,43 +438,43 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
BPackageResolvable* resolvable = providesList.ItemAt(i);
|
BPackageResolvable* resolvable = providesList.ItemAt(i);
|
||||||
bool hasVersion = resolvable->Version().InitCheck() == B_OK;
|
bool hasVersion = resolvable->Version().InitCheck() == B_OK;
|
||||||
|
|
||||||
PackageAttribute* providesType = new PackageAttribute(
|
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES_TYPE, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
|
||||||
providesType->unsignedInt = resolvable->Type();
|
|
||||||
attributeList.Add(providesType);
|
|
||||||
|
|
||||||
PackageAttribute* provides = new PackageAttribute(
|
PackageAttribute* provides = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_PROVIDES, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
provides->string = fPackageStringCache.Get(resolvable->Name().String());
|
provides->string = fPackageStringCache.Get(resolvable->Name().String());
|
||||||
attributeList.Add(provides);
|
attributeList.Add(provides);
|
||||||
|
|
||||||
|
PackageAttribute* providesType = new PackageAttribute(
|
||||||
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_PROVIDES_TYPE,
|
||||||
|
B_HPKG_ATTRIBUTE_TYPE_UINT, B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||||
|
providesType->unsignedInt = resolvable->Type();
|
||||||
|
provides->children.Add(providesType);
|
||||||
|
|
||||||
if (hasVersion)
|
if (hasVersion)
|
||||||
RegisterPackageVersion(provides->children, resolvable->Version());
|
RegisterPackageVersion(provides->children, resolvable->Version());
|
||||||
}
|
}
|
||||||
|
|
||||||
// requires list
|
// requires list
|
||||||
RegisterPackageResolvableExpressionList(attributeList,
|
RegisterPackageResolvableExpressionList(attributeList,
|
||||||
packageInfo.RequiresList(), HPKG_PACKAGE_ATTRIBUTE_REQUIRES);
|
packageInfo.RequiresList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_REQUIRES);
|
||||||
|
|
||||||
// supplements list
|
// supplements list
|
||||||
RegisterPackageResolvableExpressionList(attributeList,
|
RegisterPackageResolvableExpressionList(attributeList,
|
||||||
packageInfo.SupplementsList(), HPKG_PACKAGE_ATTRIBUTE_SUPPLEMENTS);
|
packageInfo.SupplementsList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_SUPPLEMENTS);
|
||||||
|
|
||||||
// conflicts list
|
// conflicts list
|
||||||
RegisterPackageResolvableExpressionList(attributeList,
|
RegisterPackageResolvableExpressionList(attributeList,
|
||||||
packageInfo.ConflictsList(), HPKG_PACKAGE_ATTRIBUTE_CONFLICTS);
|
packageInfo.ConflictsList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_CONFLICTS);
|
||||||
|
|
||||||
// freshens list
|
// freshens list
|
||||||
RegisterPackageResolvableExpressionList(attributeList,
|
RegisterPackageResolvableExpressionList(attributeList,
|
||||||
packageInfo.FreshensList(), HPKG_PACKAGE_ATTRIBUTE_FRESHENS);
|
packageInfo.FreshensList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_FRESHENS);
|
||||||
|
|
||||||
// replaces list
|
// replaces list
|
||||||
const BObjectList<BString>& replacesList = packageInfo.ReplacesList();
|
const BObjectList<BString>& replacesList = packageInfo.ReplacesList();
|
||||||
for (int i = 0; i < replacesList.CountItems(); ++i) {
|
for (int i = 0; i < replacesList.CountItems(); ++i) {
|
||||||
PackageAttribute* replaces = new PackageAttribute(
|
PackageAttribute* replaces = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_REPLACES, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_REPLACES, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
replaces->string
|
replaces->string
|
||||||
= fPackageStringCache.Get(replacesList.ItemAt(i)->String());
|
= fPackageStringCache.Get(replacesList.ItemAt(i)->String());
|
||||||
@@ -483,7 +484,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
|||||||
// checksum (optional, only exists in repositories)
|
// checksum (optional, only exists in repositories)
|
||||||
if (packageInfo.Checksum().Length() > 0) {
|
if (packageInfo.Checksum().Length() > 0) {
|
||||||
PackageAttribute* checksum = new PackageAttribute(
|
PackageAttribute* checksum = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_CHECKSUM, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_CHECKSUM, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
checksum->string
|
checksum->string
|
||||||
= fPackageStringCache.Get(packageInfo.Checksum().String());
|
= fPackageStringCache.Get(packageInfo.Checksum().String());
|
||||||
@@ -497,28 +498,38 @@ WriterImplBase::RegisterPackageVersion(PackageAttributeList& attributeList,
|
|||||||
const BPackageVersion& version)
|
const BPackageVersion& version)
|
||||||
{
|
{
|
||||||
PackageAttribute* versionMajor = new PackageAttribute(
|
PackageAttribute* versionMajor = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MAJOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MAJOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
versionMajor->string = fPackageStringCache.Get(version.Major().String());
|
versionMajor->string = fPackageStringCache.Get(version.Major().String());
|
||||||
attributeList.Add(versionMajor);
|
attributeList.Add(versionMajor);
|
||||||
|
|
||||||
|
if (version.Minor().Length() > 0) {
|
||||||
PackageAttribute* versionMinor = new PackageAttribute(
|
PackageAttribute* versionMinor = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MINOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MINOR,
|
||||||
|
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
versionMinor->string = fPackageStringCache.Get(version.Minor().String());
|
versionMinor->string
|
||||||
attributeList.Add(versionMinor);
|
= fPackageStringCache.Get(version.Minor().String());
|
||||||
|
versionMajor->children.Add(versionMinor);
|
||||||
|
|
||||||
|
if (version.Micro().Length() > 0) {
|
||||||
PackageAttribute* versionMicro = new PackageAttribute(
|
PackageAttribute* versionMicro = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MICRO, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MICRO,
|
||||||
|
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
versionMicro->string = fPackageStringCache.Get(version.Micro().String());
|
versionMicro->string
|
||||||
attributeList.Add(versionMicro);
|
= fPackageStringCache.Get(version.Micro().String());
|
||||||
|
versionMajor->children.Add(versionMicro);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version.Release() != 0) {
|
||||||
PackageAttribute* versionRelease = new PackageAttribute(
|
PackageAttribute* versionRelease = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_RELEASE, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_RELEASE,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
B_HPKG_ATTRIBUTE_TYPE_UINT, B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||||
versionRelease->unsignedInt = version.Release();
|
versionRelease->unsignedInt = version.Release();
|
||||||
attributeList.Add(versionRelease);
|
versionMajor->children.Add(versionRelease);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -531,15 +542,15 @@ WriterImplBase::RegisterPackageResolvableExpressionList(
|
|||||||
BPackageResolvableExpression* resolvableExpr = expressionList.ItemAt(i);
|
BPackageResolvableExpression* resolvableExpr = expressionList.ItemAt(i);
|
||||||
bool hasVersion = resolvableExpr->Version().InitCheck() == B_OK;
|
bool hasVersion = resolvableExpr->Version().InitCheck() == B_OK;
|
||||||
|
|
||||||
PackageAttribute* name = new PackageAttribute(
|
PackageAttribute* name = new PackageAttribute((BHPKGAttributeID)id,
|
||||||
(HPKGPackageAttributeID)id, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||||
name->string = fPackageStringCache.Get(resolvableExpr->Name().String());
|
name->string = fPackageStringCache.Get(resolvableExpr->Name().String());
|
||||||
attributeList.Add(name);
|
attributeList.Add(name);
|
||||||
|
|
||||||
if (hasVersion) {
|
if (hasVersion) {
|
||||||
PackageAttribute* op = new PackageAttribute(
|
PackageAttribute* op = new PackageAttribute(
|
||||||
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
B_HPKG_ATTRIBUTE_ID_PACKAGE_RESOLVABLE_OPERATOR,
|
||||||
B_HPKG_ATTRIBUTE_TYPE_UINT,
|
B_HPKG_ATTRIBUTE_TYPE_UINT,
|
||||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||||
op->unsignedInt = resolvableExpr->Operator();
|
op->unsignedInt = resolvableExpr->Operator();
|
||||||
@@ -717,7 +728,7 @@ WriterImplBase::_WritePackageAttributes(
|
|||||||
uint8 encoding = attribute->ApplicableEncoding();
|
uint8 encoding = attribute->ApplicableEncoding();
|
||||||
|
|
||||||
// write tag
|
// write tag
|
||||||
WriteUnsignedLEB128(HPKG_PACKAGE_ATTRIBUTE_TAG_COMPOSE(
|
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(
|
||||||
attribute->id, attribute->type, encoding,
|
attribute->id, attribute->type, encoding,
|
||||||
!attribute->children.IsEmpty()));
|
!attribute->children.IsEmpty()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user