2009-11-13 16:45:49 +03:00
|
|
|
/*
|
2011-07-03 06:26:54 +04:00
|
|
|
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
|
2011-02-05 01:40:10 +03:00
|
|
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
2009-11-13 16:45:49 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-30 18:05:38 +03:00
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
#include <util/OpenHashTable.h>
|
|
|
|
|
2011-07-11 16:00:55 +04:00
|
|
|
#include <String.h>
|
|
|
|
|
2011-01-31 18:43:33 +03:00
|
|
|
#include <package/hpkg/PackageWriter.h>
|
2011-01-28 02:17:03 +03:00
|
|
|
#include <package/hpkg/Strings.h>
|
2011-02-08 01:25:16 +03:00
|
|
|
#include <package/hpkg/WriterImplBase.h>
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
|
2011-07-03 06:26:54 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
template<typename Value> class RangeArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
namespace BPackageKit {
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BHPKG {
|
|
|
|
|
|
|
|
|
|
|
|
class BDataReader;
|
2011-01-31 18:43:33 +03:00
|
|
|
class BErrorOutput;
|
2013-05-19 03:07:08 +04:00
|
|
|
class BPackageWriterParameters;
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
2014-07-08 23:58:10 +04:00
|
|
|
class PackageReaderImpl;
|
2011-01-30 18:05:38 +03:00
|
|
|
struct hpkg_header;
|
2013-05-18 06:11:01 +04:00
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-02-08 01:25:16 +03:00
|
|
|
class PackageWriterImpl : public WriterImplBase {
|
2011-02-10 20:16:35 +03:00
|
|
|
typedef WriterImplBase inherited;
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
public:
|
2011-01-31 18:43:33 +03:00
|
|
|
PackageWriterImpl(
|
|
|
|
BPackageWriterListener* listener);
|
2011-01-30 18:05:38 +03:00
|
|
|
~PackageWriterImpl();
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2013-05-19 03:07:08 +04:00
|
|
|
status_t Init(const char* fileName,
|
|
|
|
const BPackageWriterParameters& parameters);
|
2011-07-11 16:00:55 +04:00
|
|
|
status_t SetInstallPath(const char* installPath);
|
2011-07-11 15:55:35 +04:00
|
|
|
void SetCheckLicenses(bool checkLicenses);
|
2011-07-01 03:41:28 +04:00
|
|
|
status_t AddEntry(const char* fileName, int fd = -1);
|
2009-11-13 16:45:49 +03:00
|
|
|
status_t Finish();
|
|
|
|
|
2014-07-08 23:58:10 +04:00
|
|
|
status_t Recompress(PackageReaderImpl* reader);
|
|
|
|
// to be called after Init(); no Finish()
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
private:
|
|
|
|
struct Attribute;
|
2011-07-03 06:26:54 +04:00
|
|
|
struct PackageContentHandler;
|
2009-11-13 16:45:49 +03:00
|
|
|
struct Entry;
|
2011-01-31 18:43:33 +03:00
|
|
|
struct SubPathAdder;
|
2011-07-03 06:26:54 +04:00
|
|
|
struct HeapAttributeOffsetter;
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
typedef DoublyLinkedList<Entry> EntryList;
|
|
|
|
|
|
|
|
private:
|
2013-05-19 03:07:08 +04:00
|
|
|
status_t _Init(const char* fileName,
|
|
|
|
const BPackageWriterParameters& parameters);
|
2009-11-13 16:45:49 +03:00
|
|
|
status_t _Finish();
|
|
|
|
|
2014-07-08 23:58:10 +04:00
|
|
|
status_t _Recompress(PackageReaderImpl* reader);
|
|
|
|
|
2011-07-01 03:41:28 +04:00
|
|
|
status_t _RegisterEntry(const char* fileName, int fd);
|
2009-11-13 16:45:49 +03:00
|
|
|
Entry* _RegisterEntry(Entry* parent,
|
2011-07-01 03:41:28 +04:00
|
|
|
const char* name, size_t nameLength, int fd,
|
2009-11-13 16:45:49 +03:00
|
|
|
bool isImplicit);
|
|
|
|
|
2011-02-08 22:50:36 +03:00
|
|
|
status_t _CheckLicenses();
|
2011-07-03 06:26:54 +04:00
|
|
|
bool _IsEntryInPackage(const char* fileName);
|
|
|
|
|
|
|
|
void _UpdateReadPackageInfo();
|
|
|
|
void _UpdateCheckEntryCollisions();
|
|
|
|
void _UpdateCheckEntryCollisions(
|
|
|
|
Attribute* parentAttribute, int dirFD,
|
|
|
|
Entry* entry, const char* fileName,
|
|
|
|
char* pathBuffer);
|
|
|
|
void _CompactHeap();
|
|
|
|
void _AttributeRemoved(Attribute* attribute);
|
2011-02-08 22:50:36 +03:00
|
|
|
|
2013-05-18 06:11:01 +04:00
|
|
|
void _WriteTOC(hpkg_header& header, uint64& _length);
|
2009-11-13 16:45:49 +03:00
|
|
|
void _WriteAttributeChildren(Attribute* attribute);
|
|
|
|
|
2013-05-18 06:11:01 +04:00
|
|
|
void _WritePackageAttributes(hpkg_header& header,
|
|
|
|
uint64& _length);
|
2011-07-03 06:20:35 +04:00
|
|
|
uint32 _WritePackageAttributesCompressed(
|
|
|
|
uint32& _stringsLengthUncompressed,
|
|
|
|
uint32& _attributesLengthUncompressed);
|
2009-11-16 00:29:53 +03:00
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
void _AddEntry(int dirFD, Entry* entry,
|
2011-01-31 18:43:33 +03:00
|
|
|
const char* fileName, char* pathBuffer);
|
2011-07-03 06:26:54 +04:00
|
|
|
void _AddDirectoryChildren(Entry* entry, int fd,
|
|
|
|
char* pathBuffer);
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-02-12 22:21:37 +03:00
|
|
|
Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
2009-11-13 16:45:49 +03:00
|
|
|
const AttributeValue& value);
|
|
|
|
|
|
|
|
template<typename Type>
|
2011-02-12 22:21:37 +03:00
|
|
|
inline Attribute* _AddAttribute(BHPKGAttributeID attributeID,
|
2009-11-13 16:45:49 +03:00
|
|
|
Type value);
|
|
|
|
|
2011-02-12 22:21:37 +03:00
|
|
|
Attribute* _AddStringAttribute(
|
|
|
|
BHPKGAttributeID attributeID,
|
2009-11-13 16:45:49 +03:00
|
|
|
const char* value);
|
2011-02-12 22:21:37 +03:00
|
|
|
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
2009-11-13 16:45:49 +03:00
|
|
|
uint64 dataSize, uint64 dataOffset);
|
2011-02-12 22:21:37 +03:00
|
|
|
Attribute* _AddDataAttribute(BHPKGAttributeID attributeID,
|
2009-11-15 11:41:57 +03:00
|
|
|
uint64 dataSize, const uint8* data);
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
status_t _AddData(BDataReader& dataReader, off_t size);
|
2011-02-08 01:25:16 +03:00
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
private:
|
2011-01-31 18:43:33 +03:00
|
|
|
BPackageWriterListener* fListener;
|
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
off_t fHeapOffset;
|
2013-05-18 06:11:01 +04:00
|
|
|
uint16 fHeaderSize;
|
2011-07-03 06:26:54 +04:00
|
|
|
|
2013-05-18 06:11:01 +04:00
|
|
|
::BPrivate::RangeArray<uint64>* fHeapRangesToRemove;
|
2011-02-08 13:59:38 +03:00
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
Entry* fRootEntry;
|
|
|
|
|
|
|
|
Attribute* fRootAttribute;
|
|
|
|
Attribute* fTopAttribute;
|
|
|
|
|
2011-02-08 01:25:16 +03:00
|
|
|
StringCache fStringCache;
|
2011-02-08 22:50:36 +03:00
|
|
|
|
|
|
|
BPackageInfo fPackageInfo;
|
2011-07-11 16:00:55 +04:00
|
|
|
BString fInstallPath;
|
2011-07-11 15:55:35 +04:00
|
|
|
bool fCheckLicenses;
|
2009-11-13 16:45:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
} // namespace BHPKG
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
|