1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_ 7 #define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_ 8 9 10 #include <util/DoublyLinkedList.h> 11 #include <util/OpenHashTable.h> 12 13 #include <String.h> 14 15 #include <package/hpkg/PackageWriter.h> 16 #include <package/hpkg/Strings.h> 17 #include <package/hpkg/WriterImplBase.h> 18 19 20 namespace BPrivate { 21 template<typename Value> class RangeArray; 22 } 23 24 25 namespace BPackageKit { 26 27 namespace BHPKG { 28 29 30 class BDataReader; 31 class BErrorOutput; 32 class BPackageWriterParameters; 33 34 35 namespace BPrivate { 36 37 38 struct hpkg_header; 39 class PackageFileHeapWriter; 40 41 42 class PackageWriterImpl : public WriterImplBase { 43 typedef WriterImplBase inherited; 44 45 public: 46 PackageWriterImpl( 47 BPackageWriterListener* listener); 48 ~PackageWriterImpl(); 49 50 status_t Init(const char* fileName, 51 const BPackageWriterParameters& parameters); 52 status_t SetInstallPath(const char* installPath); 53 void SetCheckLicenses(bool checkLicenses); 54 status_t AddEntry(const char* fileName, int fd = -1); 55 status_t Finish(); 56 57 private: 58 struct Attribute; 59 struct PackageContentHandler; 60 struct Entry; 61 struct SubPathAdder; 62 struct HeapAttributeOffsetter; 63 64 typedef DoublyLinkedList<Entry> EntryList; 65 66 private: 67 status_t _Init(const char* fileName, 68 const BPackageWriterParameters& parameters); 69 status_t _Finish(); 70 71 status_t _RegisterEntry(const char* fileName, int fd); 72 Entry* _RegisterEntry(Entry* parent, 73 const char* name, size_t nameLength, int fd, 74 bool isImplicit); 75 76 status_t _CheckLicenses(); 77 bool _IsEntryInPackage(const char* fileName); 78 79 void _UpdateReadPackageInfo(); 80 void _UpdateCheckEntryCollisions(); 81 void _UpdateCheckEntryCollisions( 82 Attribute* parentAttribute, int dirFD, 83 Entry* entry, const char* fileName, 84 char* pathBuffer); 85 void _CompactHeap(); 86 void _AttributeRemoved(Attribute* attribute); 87 88 void _WriteTOC(hpkg_header& header, uint64& _length); 89 void _WriteAttributeChildren(Attribute* attribute); 90 91 void _WritePackageAttributes(hpkg_header& header, 92 uint64& _length); 93 uint32 _WritePackageAttributesCompressed( 94 uint32& _stringsLengthUncompressed, 95 uint32& _attributesLengthUncompressed); 96 97 void _AddEntry(int dirFD, Entry* entry, 98 const char* fileName, char* pathBuffer); 99 void _AddDirectoryChildren(Entry* entry, int fd, 100 char* pathBuffer); 101 102 Attribute* _AddAttribute(BHPKGAttributeID attributeID, 103 const AttributeValue& value); 104 105 template<typename Type> 106 inline Attribute* _AddAttribute(BHPKGAttributeID attributeID, 107 Type value); 108 109 Attribute* _AddStringAttribute( 110 BHPKGAttributeID attributeID, 111 const char* value); 112 Attribute* _AddDataAttribute(BHPKGAttributeID attributeID, 113 uint64 dataSize, uint64 dataOffset); 114 Attribute* _AddDataAttribute(BHPKGAttributeID attributeID, 115 uint64 dataSize, const uint8* data); 116 117 status_t _AddData(BDataReader& dataReader, off_t size); 118 119 status_t _WriteZlibCompressedData( 120 BDataReader& dataReader, 121 off_t size, uint64 writeOffset, 122 uint64& _compressedSize); 123 124 private: 125 BPackageWriterListener* fListener; 126 127 off_t fHeapOffset; 128 uint16 fHeaderSize; 129 130 ::BPrivate::RangeArray<uint64>* fHeapRangesToRemove; 131 132 Entry* fRootEntry; 133 134 Attribute* fRootAttribute; 135 Attribute* fTopAttribute; 136 137 StringCache fStringCache; 138 139 BPackageInfo fPackageInfo; 140 BString fInstallPath; 141 bool fCheckLicenses; 142 }; 143 144 145 } // namespace BPrivate 146 147 } // namespace BHPKG 148 149 } // namespace BPackageKit 150 151 152 #endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_ 153