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:
parent
fbd18976e8
commit
33bc4425be
@ -9,7 +9,7 @@
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
enum BPackageInfoAttributeIndex {
|
||||
enum BPackageInfoAttributeID {
|
||||
B_PACKAGE_INFO_NAME = 0,
|
||||
B_PACKAGE_INFO_SUMMARY, // single line
|
||||
B_PACKAGE_INFO_DESCRIPTION, // multiple lines possible
|
||||
|
@ -69,29 +69,49 @@ enum {
|
||||
|
||||
|
||||
// package attribute IDs
|
||||
enum BPackageAttributeID {
|
||||
B_PACKAGE_ATTRIBUTE_NAME = 0,
|
||||
B_PACKAGE_ATTRIBUTE_SUMMARY,
|
||||
B_PACKAGE_ATTRIBUTE_DESCRIPTION,
|
||||
B_PACKAGE_ATTRIBUTE_VENDOR,
|
||||
B_PACKAGE_ATTRIBUTE_PACKAGER,
|
||||
B_PACKAGE_ATTRIBUTE_ARCHITECTURE,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MAJOR,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MINOR,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_MICRO,
|
||||
B_PACKAGE_ATTRIBUTE_VERSION_RELEASE,
|
||||
B_PACKAGE_ATTRIBUTE_COPYRIGHT,
|
||||
B_PACKAGE_ATTRIBUTE_LICENSE,
|
||||
B_PACKAGE_ATTRIBUTE_PROVIDES,
|
||||
B_PACKAGE_ATTRIBUTE_PROVIDES_TYPE,
|
||||
B_PACKAGE_ATTRIBUTE_REQUIRES,
|
||||
B_PACKAGE_ATTRIBUTE_SUPPLEMENTS,
|
||||
B_PACKAGE_ATTRIBUTE_CONFLICTS,
|
||||
B_PACKAGE_ATTRIBUTE_FRESHENS,
|
||||
B_PACKAGE_ATTRIBUTE_REPLACES,
|
||||
B_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
||||
enum BHPKGAttributeID {
|
||||
B_HPKG_ATTRIBUTE_ID_DIRECTORY_ENTRY = 0,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_TYPE = 1,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_PERMISSIONS = 2,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_USER = 3,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_GROUP = 4,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATIME = 5,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_MTIME = 6,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_CRTIME = 7,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATIME_NANOS = 8,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_MTIME_NANOS = 9,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_CRTIM_NANOS = 10,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE = 11,
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE_TYPE = 12,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA = 13,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_SIZE = 14,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_COMPRESSION = 15,
|
||||
B_HPKG_ATTRIBUTE_ID_DATA_CHUNK_SIZE = 16,
|
||||
B_HPKG_ATTRIBUTE_ID_SYMLINK_PATH = 17,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_NAME = 18,
|
||||
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 {
|
||||
B_HPKG_FILE_TYPE_FILE = 0,
|
||||
B_HPKG_FILE_TYPE_DIRECTORY = 1,
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/hpkg/HPKGDefs.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
@ -24,14 +26,18 @@ class BLowLevelPackageContentHandler {
|
||||
public:
|
||||
virtual ~BLowLevelPackageContentHandler();
|
||||
|
||||
virtual status_t HandleAttribute(const char* attributeName,
|
||||
virtual status_t HandleAttribute(BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* parentToken, void*& _token) = 0;
|
||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
||||
virtual status_t HandleAttributeDone(
|
||||
BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value,
|
||||
void* token) = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
|
||||
protected:
|
||||
static const char* AttributeNameForID(uint8 id);
|
||||
};
|
||||
|
||||
|
||||
@ -47,7 +53,6 @@ public:
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value
|
||||
) = 0;
|
||||
virtual status_t HandlePackageAttributesDone() = 0;
|
||||
|
||||
virtual void HandleErrorOccurred() = 0;
|
||||
};
|
||||
|
@ -51,42 +51,52 @@ struct BPackageInfoAttributeValue {
|
||||
BPackageResolvableData resolvable;
|
||||
BPackageResolvableExpressionData resolvableExpression;
|
||||
};
|
||||
uint8 attributeIndex;
|
||||
BPackageInfoAttributeID attributeID;
|
||||
|
||||
public:
|
||||
inline BPackageInfoAttributeValue();
|
||||
BPackageInfoAttributeValue();
|
||||
|
||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
||||
void SetTo(BPackageInfoAttributeID id,
|
||||
uint8 value);
|
||||
inline void SetTo(BPackageInfoAttributeIndex index,
|
||||
void SetTo(BPackageInfoAttributeID id,
|
||||
const char* value);
|
||||
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
BPackageInfoAttributeValue::BPackageInfoAttributeValue()
|
||||
:
|
||||
attributeIndex(B_PACKAGE_INFO_ENUM_COUNT)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index, uint8 value)
|
||||
inline void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, uint8 value)
|
||||
{
|
||||
attributeIndex = index;
|
||||
attributeID = id;
|
||||
unsignedInt = value;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeIndex index,
|
||||
inline void
|
||||
BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id,
|
||||
const char* value)
|
||||
{
|
||||
attributeIndex = index;
|
||||
attributeID = id;
|
||||
string = value;
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BPackageInfoAttributeValue::Clear()
|
||||
{
|
||||
memset(this, 0, sizeof(BPackageInfoAttributeValue));
|
||||
attributeID = B_PACKAGE_INFO_ENUM_COUNT;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
@ -29,9 +29,7 @@ public:
|
||||
|
||||
virtual void OnEntryAdded(const char* path) = 0;
|
||||
|
||||
virtual void OnTOCSizeInfo(
|
||||
uint64 uncompressedAttributeTypesSize,
|
||||
uint64 uncompressedStringsSize,
|
||||
virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
|
||||
uint64 uncompressedMainSize,
|
||||
uint64 uncompressedTOCSize) = 0;
|
||||
virtual void OnPackageAttributesSizeInfo(uint32 stringCount,
|
||||
|
40
headers/os/package/hpkg/RepositoryContentHandler.h
Normal file
40
headers/os/package/hpkg/RepositoryContentHandler.h
Normal file
@ -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_
|
45
headers/os/package/hpkg/RepositoryReader.h
Normal file
45
headers/os/package/hpkg/RepositoryReader.h
Normal file
@ -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_
|
87
headers/private/package/hpkg/HPKGDefsPrivate.h
Normal file
87
headers/private/package/hpkg/HPKGDefsPrivate.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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; }
|
||||
|
||||
private:
|
||||
struct AttributeType;
|
||||
struct AttributeTypeReference;
|
||||
struct AttributeHandlerContext;
|
||||
struct AttributeHandler;
|
||||
struct IgnoreAttributeHandler;
|
||||
struct DataAttributeHandler;
|
||||
struct AttributeAttributeHandler;
|
||||
struct EntryAttributeHandler;
|
||||
struct RootAttributeHandler;
|
||||
struct PackageAttributeHandler;
|
||||
struct PackageVersionAttributeHandler;
|
||||
struct PackageResolvableAttributeHandler;
|
||||
struct PackageResolvableExpressionAttributeHandler;
|
||||
struct RootAttributeHandler;
|
||||
struct LowLevelAttributeHandler;
|
||||
struct PackageContentListHandler;
|
||||
|
||||
struct SectionInfo {
|
||||
@ -94,8 +96,6 @@ private:
|
||||
const char* _CheckCompression(
|
||||
const SectionInfo& section) const;
|
||||
|
||||
status_t _ParseTOCAttributeTypes();
|
||||
|
||||
status_t _ParseStrings();
|
||||
|
||||
status_t _ParseContent(AttributeHandlerContext* context,
|
||||
@ -117,7 +117,7 @@ private:
|
||||
const char* resolvableName,
|
||||
bool hasChildren);
|
||||
|
||||
status_t _ReadPackageAttribute(uint8& _id,
|
||||
status_t _ReadAttribute(uint8& _id,
|
||||
AttributeValue& _value,
|
||||
bool* _hasChildren = NULL,
|
||||
uint64* _tag = NULL);
|
||||
@ -141,8 +141,6 @@ private:
|
||||
status_t _ReadCompressedBuffer(
|
||||
const SectionInfo& section);
|
||||
|
||||
static int8 _GetStandardIndex(const AttributeType* type);
|
||||
|
||||
inline AttributeHandler* _CurrentAttributeHandler() const;
|
||||
inline void _PushAttributeHandler(
|
||||
AttributeHandler* handler);
|
||||
@ -157,15 +155,10 @@ private:
|
||||
uint64 fHeapOffset;
|
||||
uint64 fHeapSize;
|
||||
|
||||
uint64 fTOCAttributeTypesLength;
|
||||
uint64 fTOCAttributeTypesCount;
|
||||
|
||||
SectionInfo fTOCSection;
|
||||
SectionInfo fPackageAttributesSection;
|
||||
SectionInfo* fCurrentSection;
|
||||
|
||||
AttributeTypeReference* fAttributeTypes;
|
||||
|
||||
AttributeHandlerList* fAttributeHandlerStack;
|
||||
|
||||
uint8* fScratchBuffer;
|
||||
|
@ -42,16 +42,10 @@ public:
|
||||
status_t Finish();
|
||||
|
||||
private:
|
||||
struct AttributeTypeKey;
|
||||
struct AttributeType;
|
||||
struct AttributeTypeHashDefinition;
|
||||
struct Attribute;
|
||||
struct AttributeTypeUsageGreater;
|
||||
struct Entry;
|
||||
struct SubPathAdder;
|
||||
|
||||
typedef BOpenHashTable<AttributeTypeHashDefinition>
|
||||
AttributeTypeTable;
|
||||
typedef DoublyLinkedList<Entry> EntryList;
|
||||
|
||||
private:
|
||||
@ -66,9 +60,8 @@ private:
|
||||
status_t _CheckLicenses();
|
||||
|
||||
void _WriteTOC(hpkg_header& header);
|
||||
int32 _WriteTOCSections(uint64& _attributeTypesSize,
|
||||
uint64& _stringsSize, uint64& _mainSize);
|
||||
void _WriteAttributeTypes();
|
||||
int32 _WriteTOCSections(uint64& _stringsSize,
|
||||
uint64& _mainSize);
|
||||
void _WriteAttributeChildren(Attribute* attribute);
|
||||
|
||||
void _WritePackageAttributes(hpkg_header& header);
|
||||
@ -76,23 +69,21 @@ private:
|
||||
void _AddEntry(int dirFD, Entry* entry,
|
||||
const char* fileName, char* pathBuffer);
|
||||
|
||||
Attribute* _AddAttribute(const char* attributeName,
|
||||
Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||
const AttributeValue& value);
|
||||
|
||||
template<typename Type>
|
||||
inline Attribute* _AddAttribute(const char* attributeName,
|
||||
inline Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
||||
Type value);
|
||||
|
||||
Attribute* _AddStringAttribute(const char* attributeName,
|
||||
Attribute* _AddStringAttribute(
|
||||
BHPKGAttributeID attributeID,
|
||||
const char* value);
|
||||
Attribute* _AddDataAttribute(const char* attributeName,
|
||||
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, uint64 dataOffset);
|
||||
Attribute* _AddDataAttribute(const char* attributeName,
|
||||
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, const uint8* data);
|
||||
|
||||
AttributeType* _GetAttributeType(const char* attributeName,
|
||||
uint8 type);
|
||||
|
||||
status_t _AddData(BDataReader& dataReader, off_t size);
|
||||
|
||||
status_t _WriteUncompressedData(BDataReader& dataReader,
|
||||
@ -117,7 +108,6 @@ private:
|
||||
Attribute* fTopAttribute;
|
||||
|
||||
StringCache fStringCache;
|
||||
AttributeTypeTable* fAttributeTypes;
|
||||
|
||||
BPackageInfo fPackageInfo;
|
||||
};
|
||||
|
190
headers/private/package/hpkg/RepositoryReaderImpl.h
Normal file
190
headers/private/package/hpkg/RepositoryReaderImpl.h
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* 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 <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/DataOutput.h>
|
||||
#include <package/hpkg/Strings.h>
|
||||
@ -79,10 +79,10 @@ protected:
|
||||
struct PackageAttribute :
|
||||
public DoublyLinkedListLinkImpl<PackageAttribute>,
|
||||
public AttributeValue {
|
||||
HPKGPackageAttributeID id;
|
||||
BHPKGAttributeID id;
|
||||
DoublyLinkedList<PackageAttribute> children;
|
||||
|
||||
PackageAttribute(HPKGPackageAttributeID id_, uint8 type,
|
||||
PackageAttribute(BHPKGAttributeID id_, uint8 type,
|
||||
uint8 encoding);
|
||||
~PackageAttribute();
|
||||
|
||||
|
@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* 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 <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
|
||||
static const uint32 kMaxCachedBuffers = 32;
|
||||
|
@ -264,12 +264,6 @@ struct Volume::PackageLoaderContentHandler : BPackageContentHandler {
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t HandlePackageAttributesDone()
|
||||
{
|
||||
// TODO!
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual void HandleErrorOccurred()
|
||||
{
|
||||
fErrorOccurred = true;
|
||||
|
@ -46,16 +46,13 @@ public:
|
||||
printf("\t%s\n", path);
|
||||
}
|
||||
|
||||
virtual void OnTOCSizeInfo(uint64 uncompressedAttributeTypesSize,
|
||||
uint64 uncompressedStringsSize, uint64 uncompressedMainSize,
|
||||
uint64 uncompressedTOCSize)
|
||||
virtual void OnTOCSizeInfo(uint64 uncompressedStringsSize,
|
||||
uint64 uncompressedMainSize, uint64 uncompressedTOCSize)
|
||||
{
|
||||
if (fQuiet || !fVerbose)
|
||||
return;
|
||||
|
||||
printf("----- TOC Info -----------------------------------\n");
|
||||
printf("attribute types size: %10llu (uncompressed)\n",
|
||||
uncompressedAttributeTypesSize);
|
||||
printf("cached strings size: %10llu (uncompressed)\n",
|
||||
uncompressedStringsSize);
|
||||
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)
|
||||
{
|
||||
if (fErrorOccurred)
|
||||
return B_OK;
|
||||
|
||||
printf("%*s>%s: ", fLevel * 2, "", attributeName);
|
||||
printf("%*s>%s: ", fLevel * 2, "", AttributeNameForID(attributeID));
|
||||
_PrintValue(value);
|
||||
printf("\n");
|
||||
|
||||
@ -49,7 +49,7 @@ struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t HandleAttributeDone(const char* attributeName,
|
||||
virtual status_t HandleAttributeDone(BHPKGAttributeID attributeID,
|
||||
const BPackageAttributeValue& value, void* token)
|
||||
{
|
||||
if (fErrorOccurred)
|
||||
@ -58,7 +58,7 @@ struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
|
||||
fLevel--;
|
||||
|
||||
if (fHasChildren)
|
||||
printf("%*s<%s\n", fLevel * 2, "", attributeName);
|
||||
printf("%*s<%s\n", fLevel * 2, "", AttributeNameForID(attributeID));
|
||||
|
||||
fHasChildren = true;
|
||||
return B_OK;
|
||||
@ -144,14 +144,12 @@ command_dump(int argc, const char* const* argv)
|
||||
StandardErrorOutput errorOutput;
|
||||
BPackageReader packageReader(&errorOutput);
|
||||
status_t error = packageReader.Init(packageFileName);
|
||||
printf("Init(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
|
||||
// list
|
||||
PackageContentDumpHandler handler;
|
||||
error = packageReader.ParseContent(&handler);
|
||||
printf("ParseContent(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
|
||||
|
@ -229,11 +229,6 @@ struct PackageContentExtractHandler : BPackageContentHandler {
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t HandlePackageAttributesDone()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual void HandleErrorOccurred()
|
||||
{
|
||||
fErrorOccurred = true;
|
||||
|
@ -111,7 +111,7 @@ struct PackageContentListHandler : BPackageContentHandler {
|
||||
virtual status_t HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value)
|
||||
{
|
||||
switch (value.attributeIndex) {
|
||||
switch (value.attributeID) {
|
||||
case B_PACKAGE_INFO_NAME:
|
||||
printf("package-attributes:\n");
|
||||
printf("\tname: %s\n", value.string);
|
||||
@ -218,19 +218,13 @@ struct PackageContentListHandler : BPackageContentHandler {
|
||||
default:
|
||||
printf(
|
||||
"*** Invalid package attribute section: unexpected "
|
||||
"package attribute index %d encountered\n",
|
||||
value.attributeIndex);
|
||||
"package attribute id %d encountered\n", value.attributeID);
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual status_t HandlePackageAttributesDone()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
virtual void HandleErrorOccurred()
|
||||
{
|
||||
}
|
||||
@ -308,14 +302,12 @@ command_list(int argc, const char* const* argv)
|
||||
StandardErrorOutput errorOutput;
|
||||
BPackageReader packageReader(&errorOutput);
|
||||
status_t error = packageReader.Init(packageFileName);
|
||||
printf("Init(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
|
||||
// list
|
||||
PackageContentListHandler handler(listAttributes);
|
||||
error = packageReader.ParseContent(&handler);
|
||||
printf("ParseContent(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
using namespace BPackageKit::BHPKG;
|
||||
using namespace BPackageKit;
|
||||
|
||||
|
||||
/*
|
||||
struct PackageContentListHandler : BPackageContentHandler {
|
||||
PackageContentListHandler(bool listAttributes)
|
||||
:
|
||||
@ -265,7 +265,7 @@ private:
|
||||
int fLevel;
|
||||
bool fListAttribute;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
int
|
||||
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++];
|
||||
|
||||
// open package
|
||||
StandardErrorOutput errorOutput;
|
||||
BPackageReader packageReader(&errorOutput);
|
||||
status_t error = packageReader.Init(packageFileName);
|
||||
printf("Init(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
// StandardErrorOutput errorOutput;
|
||||
// BPackageReader packageReader(&errorOutput);
|
||||
// status_t error = packageReader.Init(packageFileName);
|
||||
// if (error != B_OK)
|
||||
// return 1;
|
||||
|
||||
// list
|
||||
PackageContentListHandler handler(listAttributes);
|
||||
error = packageReader.ParseContent(&handler);
|
||||
printf("ParseContent(): %s\n", strerror(error));
|
||||
if (error != B_OK)
|
||||
return 1;
|
||||
// PackageContentListHandler handler(listAttributes);
|
||||
// error = packageReader.ParseContent(&handler);
|
||||
// if (error != B_OK)
|
||||
// return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ namespace BPackageKit {
|
||||
|
||||
|
||||
BPackageVersion::BPackageVersion()
|
||||
:
|
||||
fRelease(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,66 @@ namespace BHPKG {
|
||||
// #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()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*static*/ const char*
|
||||
BLowLevelPackageContentHandler::AttributeNameForID(uint8 id)
|
||||
{
|
||||
if (id >= B_HPKG_ATTRIBUTE_ID_ENUM_COUNT)
|
||||
return NULL;
|
||||
|
||||
return kAttributeNames[id];
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - BPackageContentHandler
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
#include <package/hpkg/BufferCache.h>
|
||||
#include <package/hpkg/CachedBuffer.h>
|
||||
#include <package/hpkg/DataOutput.h>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/DataOutput.h>
|
||||
#include <package/hpkg/DataReader.h>
|
||||
@ -52,87 +52,15 @@ static const size_t kZlibCompressionSizeThreshold = 64;
|
||||
// #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
|
||||
: public DoublyLinkedListLinkImpl<Attribute> {
|
||||
AttributeType* type;
|
||||
BHPKGAttributeID id;
|
||||
AttributeValue value;
|
||||
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
|
||||
|
||||
|
||||
@ -279,11 +199,11 @@ private:
|
||||
|
||||
template<typename Type>
|
||||
inline PackageWriterImpl::Attribute*
|
||||
PackageWriterImpl::_AddAttribute(const char* attributeName, Type value)
|
||||
PackageWriterImpl::_AddAttribute(BHPKGAttributeID attributeID, Type value)
|
||||
{
|
||||
AttributeValue attributeValue;
|
||||
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),
|
||||
fRootEntry(NULL),
|
||||
fRootAttribute(NULL),
|
||||
fTopAttribute(NULL),
|
||||
fAttributeTypes(NULL)
|
||||
fTopAttribute(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -308,15 +227,6 @@ PackageWriterImpl::~PackageWriterImpl()
|
||||
{
|
||||
delete fRootAttribute;
|
||||
|
||||
if (fAttributeTypes != NULL) {
|
||||
AttributeType* attributeType = fAttributeTypes->Clear(true);
|
||||
while (attributeType != NULL) {
|
||||
AttributeType* next = attributeType->next;
|
||||
delete attributeType;
|
||||
attributeType = next;
|
||||
}
|
||||
}
|
||||
|
||||
delete fRootEntry;
|
||||
|
||||
free(fDataBuffer);
|
||||
@ -409,14 +319,10 @@ PackageWriterImpl::_Init(const char* fileName)
|
||||
if (fStringCache.Init() != B_OK)
|
||||
throw std::bad_alloc();
|
||||
|
||||
fAttributeTypes = new AttributeTypeTable;
|
||||
if (fAttributeTypes->Init() != B_OK)
|
||||
throw std::bad_alloc();
|
||||
|
||||
// create entry list
|
||||
fRootEntry = new Entry(NULL, 0, true);
|
||||
|
||||
fRootAttribute = new Attribute(NULL);
|
||||
fRootAttribute = new Attribute();
|
||||
|
||||
fHeapOffset = fHeapEnd = sizeof(hpkg_header);
|
||||
fTopAttribute = fRootAttribute;
|
||||
@ -587,12 +493,10 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
||||
zlibWriter.Init();
|
||||
|
||||
// write the sections
|
||||
uint64 uncompressedAttributeTypesSize;
|
||||
uint64 uncompressedStringsSize;
|
||||
uint64 uncompressedMainSize;
|
||||
int32 cachedStringsWritten = _WriteTOCSections(
|
||||
uncompressedAttributeTypesSize, uncompressedStringsSize,
|
||||
uncompressedMainSize);
|
||||
int32 cachedStringsWritten
|
||||
= _WriteTOCSections(uncompressedStringsSize, uncompressedMainSize);
|
||||
|
||||
// finish the writer
|
||||
zlibWriter.Finish();
|
||||
@ -601,8 +505,7 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
||||
|
||||
off_t endOffset = fHeapEnd;
|
||||
|
||||
fListener->OnTOCSizeInfo(uncompressedAttributeTypesSize,
|
||||
uncompressedStringsSize, uncompressedMainSize,
|
||||
fListener->OnTOCSizeInfo(uncompressedStringsSize, uncompressedMainSize,
|
||||
zlibWriter.BytesWritten());
|
||||
|
||||
// update the header
|
||||
@ -615,10 +518,6 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
||||
zlibWriter.BytesWritten());
|
||||
|
||||
// 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(
|
||||
uncompressedStringsSize);
|
||||
header.toc_strings_count = B_HOST_TO_BENDIAN_INT64(cachedStringsWritten);
|
||||
@ -626,13 +525,8 @@ PackageWriterImpl::_WriteTOC(hpkg_header& header)
|
||||
|
||||
|
||||
int32
|
||||
PackageWriterImpl::_WriteTOCSections(uint64& _attributeTypesSize,
|
||||
uint64& _stringsSize, uint64& _mainSize)
|
||||
PackageWriterImpl::_WriteTOCSections(uint64& _stringsSize, uint64& _mainSize)
|
||||
{
|
||||
// write the attribute type abbreviations
|
||||
uint64 attributeTypesOffset = DataWriter()->BytesWritten();
|
||||
_WriteAttributeTypes();
|
||||
|
||||
// write the cached strings
|
||||
uint64 cachedStringsOffset = DataWriter()->BytesWritten();
|
||||
int32 cachedStringsWritten = WriteCachedStrings(fStringCache, 2);
|
||||
@ -641,7 +535,6 @@ PackageWriterImpl::_WriteTOCSections(uint64& _attributeTypesSize,
|
||||
uint64 mainOffset = DataWriter()->BytesWritten();
|
||||
_WriteAttributeChildren(fRootAttribute);
|
||||
|
||||
_attributeTypesSize = cachedStringsOffset - attributeTypesOffset;
|
||||
_stringsSize = mainOffset - cachedStringsOffset;
|
||||
_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
|
||||
PackageWriterImpl::_WriteAttributeChildren(Attribute* attribute)
|
||||
{
|
||||
DoublyLinkedList<Attribute>::Iterator it
|
||||
= attribute->children.GetIterator();
|
||||
while (Attribute* child = it.Next()) {
|
||||
AttributeType* type = child->type;
|
||||
|
||||
// write tag
|
||||
uint8 encoding = child->value.ApplicableEncoding();
|
||||
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(type->index,
|
||||
encoding, !child->children.IsEmpty()));
|
||||
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(child->id,
|
||||
child->value.type, encoding, !child->children.IsEmpty()));
|
||||
|
||||
// write value
|
||||
WriteAttributeValue(child->value, encoding);
|
||||
@ -800,19 +659,19 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
||||
|
||||
// add attribute entry
|
||||
Attribute* entryAttribute = _AddStringAttribute(
|
||||
HPKG_ATTRIBUTE_NAME_DIRECTORY_ENTRY, fileName);
|
||||
B_HPKG_ATTRIBUTE_ID_DIRECTORY_ENTRY, fileName);
|
||||
Stacker<Attribute> entryAttributeStacker(fTopAttribute, entryAttribute);
|
||||
|
||||
// add stat data
|
||||
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)) {
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_PERMISSIONS,
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_PERMISSIONS,
|
||||
uint32(st.st_mode & ALLPERMS));
|
||||
}
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_ATIME, uint32(st.st_atime));
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_MTIME, uint32(st.st_mtime));
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_CRTIME, uint32(st.st_crtime));
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_ATIME, uint32(st.st_atime));
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_MTIME, uint32(st.st_mtime));
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_CRTIME, uint32(st.st_crtime));
|
||||
// TODO: File user/group!
|
||||
|
||||
// add file data/symlink path
|
||||
@ -836,7 +695,7 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
||||
}
|
||||
|
||||
path[bytesRead] = '\0';
|
||||
_AddStringAttribute(HPKG_ATTRIBUTE_NAME_SYMLINK_PATH, path);
|
||||
_AddStringAttribute(B_HPKG_ATTRIBUTE_ID_SYMLINK_PATH, path);
|
||||
}
|
||||
|
||||
// add attributes
|
||||
@ -854,12 +713,12 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
||||
|
||||
// create attribute entry
|
||||
Attribute* attributeAttribute = _AddStringAttribute(
|
||||
HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE, entry->d_name);
|
||||
B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE, entry->d_name);
|
||||
Stacker<Attribute> attributeAttributeStacker(fTopAttribute,
|
||||
attributeAttribute);
|
||||
|
||||
// add type
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_FILE_ATTRIBUTE_TYPE,
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_FILE_ATTRIBUTE_TYPE,
|
||||
(uint32)attrInfo.type);
|
||||
|
||||
// add data
|
||||
@ -912,11 +771,10 @@ PackageWriterImpl::_AddEntry(int dirFD, Entry* entry, const char* fileName,
|
||||
|
||||
|
||||
PackageWriterImpl::Attribute*
|
||||
PackageWriterImpl::_AddAttribute(const char* attributeName,
|
||||
PackageWriterImpl::_AddAttribute(BHPKGAttributeID id,
|
||||
const AttributeValue& value)
|
||||
{
|
||||
Attribute* attribute = new Attribute(
|
||||
_GetAttributeType(attributeName, value.type));
|
||||
Attribute* attribute = new Attribute(id);
|
||||
|
||||
attribute->value = value;
|
||||
fTopAttribute->AddChild(attribute);
|
||||
@ -926,53 +784,32 @@ PackageWriterImpl::_AddAttribute(const char* attributeName,
|
||||
|
||||
|
||||
PackageWriterImpl::Attribute*
|
||||
PackageWriterImpl::_AddStringAttribute(const char* attributeName,
|
||||
PackageWriterImpl::_AddStringAttribute(BHPKGAttributeID attributeID,
|
||||
const char* value)
|
||||
{
|
||||
AttributeValue attributeValue;
|
||||
attributeValue.SetTo(fStringCache.Get(value));
|
||||
return _AddAttribute(attributeName, attributeValue);
|
||||
return _AddAttribute(attributeID, attributeValue);
|
||||
}
|
||||
|
||||
|
||||
PackageWriterImpl::Attribute*
|
||||
PackageWriterImpl::_AddDataAttribute(const char* attributeName, uint64 dataSize,
|
||||
uint64 dataOffset)
|
||||
PackageWriterImpl::_AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, uint64 dataOffset)
|
||||
{
|
||||
AttributeValue attributeValue;
|
||||
attributeValue.SetToData(dataSize, dataOffset);
|
||||
return _AddAttribute(attributeName, attributeValue);
|
||||
return _AddAttribute(attributeID, attributeValue);
|
||||
}
|
||||
|
||||
|
||||
PackageWriterImpl::Attribute*
|
||||
PackageWriterImpl::_AddDataAttribute(const char* attributeName, uint64 dataSize,
|
||||
const uint8* data)
|
||||
PackageWriterImpl::_AddDataAttribute(BHPKGAttributeID attributeID,
|
||||
uint64 dataSize, const uint8* data)
|
||||
{
|
||||
AttributeValue attributeValue;
|
||||
attributeValue.SetToData(dataSize, data);
|
||||
return _AddAttribute(attributeName, 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;
|
||||
return _AddAttribute(attributeID, attributeValue);
|
||||
}
|
||||
|
||||
|
||||
@ -988,7 +825,7 @@ PackageWriterImpl::_AddData(BDataReader& dataReader, off_t size)
|
||||
return error;
|
||||
}
|
||||
|
||||
_AddDataAttribute(HPKG_ATTRIBUTE_NAME_DATA, size, buffer);
|
||||
_AddDataAttribute(B_HPKG_ATTRIBUTE_ID_DATA, size, buffer);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@ -1012,14 +849,14 @@ PackageWriterImpl::_AddData(BDataReader& dataReader, off_t size)
|
||||
fHeapEnd = dataOffset + compressedSize;
|
||||
|
||||
// add data attribute
|
||||
Attribute* dataAttribute = _AddDataAttribute(HPKG_ATTRIBUTE_NAME_DATA,
|
||||
Attribute* dataAttribute = _AddDataAttribute(B_HPKG_ATTRIBUTE_ID_DATA,
|
||||
compressedSize, dataOffset - fHeapOffset);
|
||||
Stacker<Attribute> attributeAttributeStacker(fTopAttribute, dataAttribute);
|
||||
|
||||
// if compressed, add compression attributes
|
||||
if (compression != B_HPKG_COMPRESSION_NONE) {
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_DATA_COMPRESSION, compression);
|
||||
_AddAttribute(HPKG_ATTRIBUTE_NAME_DATA_SIZE, (uint64)size);
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_DATA_COMPRESSION, compression);
|
||||
_AddAttribute(B_HPKG_ATTRIBUTE_ID_DATA_SIZE, (uint64)size);
|
||||
// uncompressed size
|
||||
}
|
||||
|
||||
|
55
src/kits/package/hpkg/RepositoryReader.cpp
Normal file
55
src/kits/package/hpkg/RepositoryReader.cpp
Normal file
@ -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
|
1804
src/kits/package/hpkg/RepositoryReaderImpl.cpp
Normal file
1804
src/kits/package/hpkg/RepositoryReaderImpl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||
#include <package/hpkg/PackageReader.h>
|
||||
#include <package/ChecksumAccessors.h>
|
||||
@ -122,7 +122,7 @@ status_t
|
||||
RepositoryWriterImpl::HandlePackageAttribute(
|
||||
const BPackageInfoAttributeValue& value)
|
||||
{
|
||||
switch (value.attributeIndex) {
|
||||
switch (value.attributeID) {
|
||||
case B_PACKAGE_INFO_NAME:
|
||||
fPackageInfo.SetName(value.string);
|
||||
break;
|
||||
@ -191,7 +191,7 @@ RepositoryWriterImpl::HandlePackageAttribute(
|
||||
default:
|
||||
fListener->PrintError(
|
||||
"Invalid package attribute section: unexpected package "
|
||||
"attribute index %d encountered\n", value.attributeIndex);
|
||||
"attribute id %d encountered\n", value.attributeID);
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
#include <package/hpkg/haiku_package.h>
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/DataReader.h>
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
@ -276,7 +276,7 @@ WriterImplBase::ZlibDataWriter::WriteData(const void* buffer, size_t size)
|
||||
|
||||
// #pragma mark - PackageAttribute
|
||||
|
||||
WriterImplBase::PackageAttribute::PackageAttribute(HPKGPackageAttributeID id_,
|
||||
WriterImplBase::PackageAttribute::PackageAttribute(BHPKGAttributeID id_,
|
||||
uint8 type_, uint8 encoding_)
|
||||
:
|
||||
id(id_)
|
||||
@ -357,21 +357,22 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
const BPackageInfo& packageInfo)
|
||||
{
|
||||
// name
|
||||
PackageAttribute* name = new PackageAttribute(HPKG_PACKAGE_ATTRIBUTE_NAME,
|
||||
B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
PackageAttribute* name = new PackageAttribute(
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_NAME, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
name->string = fPackageStringCache.Get(packageInfo.Name().String());
|
||||
attributeList.Add(name);
|
||||
|
||||
// summary
|
||||
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);
|
||||
summary->string = fPackageStringCache.Get(packageInfo.Summary().String());
|
||||
attributeList.Add(summary);
|
||||
|
||||
// description
|
||||
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);
|
||||
description->string
|
||||
= fPackageStringCache.Get(packageInfo.Description().String());
|
||||
@ -379,28 +380,28 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
|
||||
// vendor
|
||||
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);
|
||||
vendor->string = fPackageStringCache.Get(packageInfo.Vendor().String());
|
||||
attributeList.Add(vendor);
|
||||
|
||||
// packager
|
||||
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);
|
||||
packager->string = fPackageStringCache.Get(packageInfo.Packager().String());
|
||||
attributeList.Add(packager);
|
||||
|
||||
// flags
|
||||
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);
|
||||
flags->unsignedInt = packageInfo.Flags();
|
||||
attributeList.Add(flags);
|
||||
|
||||
// architecture
|
||||
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);
|
||||
architecture->unsignedInt = packageInfo.Architecture();
|
||||
attributeList.Add(architecture);
|
||||
@ -412,7 +413,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
const BObjectList<BString>& copyrightList = packageInfo.CopyrightList();
|
||||
for (int i = 0; i < copyrightList.CountItems(); ++i) {
|
||||
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);
|
||||
copyright->string
|
||||
= fPackageStringCache.Get(copyrightList.ItemAt(i)->String());
|
||||
@ -423,7 +424,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
const BObjectList<BString>& licenseList = packageInfo.LicenseList();
|
||||
for (int i = 0; i < licenseList.CountItems(); ++i) {
|
||||
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);
|
||||
license->string
|
||||
= fPackageStringCache.Get(licenseList.ItemAt(i)->String());
|
||||
@ -437,43 +438,43 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
BPackageResolvable* resolvable = providesList.ItemAt(i);
|
||||
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(
|
||||
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);
|
||||
provides->string = fPackageStringCache.Get(resolvable->Name().String());
|
||||
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)
|
||||
RegisterPackageVersion(provides->children, resolvable->Version());
|
||||
}
|
||||
|
||||
// requires list
|
||||
RegisterPackageResolvableExpressionList(attributeList,
|
||||
packageInfo.RequiresList(), HPKG_PACKAGE_ATTRIBUTE_REQUIRES);
|
||||
packageInfo.RequiresList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_REQUIRES);
|
||||
|
||||
// supplements list
|
||||
RegisterPackageResolvableExpressionList(attributeList,
|
||||
packageInfo.SupplementsList(), HPKG_PACKAGE_ATTRIBUTE_SUPPLEMENTS);
|
||||
packageInfo.SupplementsList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_SUPPLEMENTS);
|
||||
|
||||
// conflicts list
|
||||
RegisterPackageResolvableExpressionList(attributeList,
|
||||
packageInfo.ConflictsList(), HPKG_PACKAGE_ATTRIBUTE_CONFLICTS);
|
||||
packageInfo.ConflictsList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_CONFLICTS);
|
||||
|
||||
// freshens list
|
||||
RegisterPackageResolvableExpressionList(attributeList,
|
||||
packageInfo.FreshensList(), HPKG_PACKAGE_ATTRIBUTE_FRESHENS);
|
||||
packageInfo.FreshensList(), B_HPKG_ATTRIBUTE_ID_PACKAGE_FRESHENS);
|
||||
|
||||
// replaces list
|
||||
const BObjectList<BString>& replacesList = packageInfo.ReplacesList();
|
||||
for (int i = 0; i < replacesList.CountItems(); ++i) {
|
||||
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);
|
||||
replaces->string
|
||||
= fPackageStringCache.Get(replacesList.ItemAt(i)->String());
|
||||
@ -483,7 +484,7 @@ WriterImplBase::RegisterPackageInfo(PackageAttributeList& attributeList,
|
||||
// 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_ID_PACKAGE_CHECKSUM, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
checksum->string
|
||||
= fPackageStringCache.Get(packageInfo.Checksum().String());
|
||||
@ -497,28 +498,38 @@ WriterImplBase::RegisterPackageVersion(PackageAttributeList& attributeList,
|
||||
const BPackageVersion& version)
|
||||
{
|
||||
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);
|
||||
versionMajor->string = fPackageStringCache.Get(version.Major().String());
|
||||
attributeList.Add(versionMajor);
|
||||
|
||||
PackageAttribute* versionMinor = new PackageAttribute(
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MINOR, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
versionMinor->string = fPackageStringCache.Get(version.Minor().String());
|
||||
attributeList.Add(versionMinor);
|
||||
if (version.Minor().Length() > 0) {
|
||||
PackageAttribute* versionMinor = new PackageAttribute(
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MINOR,
|
||||
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
versionMinor->string
|
||||
= fPackageStringCache.Get(version.Minor().String());
|
||||
versionMajor->children.Add(versionMinor);
|
||||
|
||||
PackageAttribute* versionMicro = new PackageAttribute(
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_MICRO, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
versionMicro->string = fPackageStringCache.Get(version.Micro().String());
|
||||
attributeList.Add(versionMicro);
|
||||
if (version.Micro().Length() > 0) {
|
||||
PackageAttribute* versionMicro = new PackageAttribute(
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_MICRO,
|
||||
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
versionMicro->string
|
||||
= fPackageStringCache.Get(version.Micro().String());
|
||||
versionMajor->children.Add(versionMicro);
|
||||
}
|
||||
}
|
||||
|
||||
PackageAttribute* versionRelease = new PackageAttribute(
|
||||
HPKG_PACKAGE_ATTRIBUTE_VERSION_RELEASE, B_HPKG_ATTRIBUTE_TYPE_UINT,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||
versionRelease->unsignedInt = version.Release();
|
||||
attributeList.Add(versionRelease);
|
||||
if (version.Release() != 0) {
|
||||
PackageAttribute* versionRelease = new PackageAttribute(
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_VERSION_RELEASE,
|
||||
B_HPKG_ATTRIBUTE_TYPE_UINT, B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||
versionRelease->unsignedInt = version.Release();
|
||||
versionMajor->children.Add(versionRelease);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -531,15 +542,15 @@ WriterImplBase::RegisterPackageResolvableExpressionList(
|
||||
BPackageResolvableExpression* resolvableExpr = expressionList.ItemAt(i);
|
||||
bool hasVersion = resolvableExpr->Version().InitCheck() == B_OK;
|
||||
|
||||
PackageAttribute* name = new PackageAttribute(
|
||||
(HPKGPackageAttributeID)id, B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
PackageAttribute* name = new PackageAttribute((BHPKGAttributeID)id,
|
||||
B_HPKG_ATTRIBUTE_TYPE_STRING,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE);
|
||||
name->string = fPackageStringCache.Get(resolvableExpr->Name().String());
|
||||
attributeList.Add(name);
|
||||
|
||||
if (hasVersion) {
|
||||
PackageAttribute* op = new PackageAttribute(
|
||||
HPKG_PACKAGE_ATTRIBUTE_RESOLVABLE_OPERATOR,
|
||||
B_HPKG_ATTRIBUTE_ID_PACKAGE_RESOLVABLE_OPERATOR,
|
||||
B_HPKG_ATTRIBUTE_TYPE_UINT,
|
||||
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT);
|
||||
op->unsignedInt = resolvableExpr->Operator();
|
||||
@ -717,7 +728,7 @@ WriterImplBase::_WritePackageAttributes(
|
||||
uint8 encoding = attribute->ApplicableEncoding();
|
||||
|
||||
// write tag
|
||||
WriteUnsignedLEB128(HPKG_PACKAGE_ATTRIBUTE_TAG_COMPOSE(
|
||||
WriteUnsignedLEB128(HPKG_ATTRIBUTE_TAG_COMPOSE(
|
||||
attribute->id, attribute->type, encoding,
|
||||
!attribute->children.IsEmpty()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user