Add support for adding/updating package entries

Add flags parameter to BPackageWriter::Init() (and the private
implementation classes) to indicate that an existing package file shall
be updated instead of created. Currently that always happens in-place.
This commit is contained in:
Ingo Weinhold
2011-11-25 06:18:58 +01:00
parent de9e64b235
commit 00bc8e9cbd
8 changed files with 881 additions and 54 deletions
+11
View File
@@ -157,6 +157,17 @@ enum {
};
// Writer Init() flags
enum {
B_HPKG_WRITER_UPDATE_PACKAGE = 0x01,
// update the package (don't truncate)
B_HPKG_WRITER_FORCE_ADD = 0x02,
// when updating a pre-existing entry, don't fail, but replace the
// entry, if possible (directories will be merged, but won't replace a
// non-directory)
};
} // namespace BHPKG
} // namespace BPackageKit
+1 -1
View File
@@ -47,7 +47,7 @@ public:
BPackageWriterListener* listener);
~BPackageWriter();
status_t Init(const char* fileName);
status_t Init(const char* fileName, uint32 flags = 0);
status_t AddEntry(const char* fileName, int fd = -1);
status_t Finish();
@@ -1,5 +1,5 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Copyright 2011, Ingo Weinhold, [email protected].
* Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -15,6 +15,11 @@
#include <package/hpkg/WriterImplBase.h>
namespace BPrivate {
template<typename Value> class RangeArray;
}
namespace BPackageKit {
namespace BHPKG {
@@ -37,19 +42,21 @@ public:
BPackageWriterListener* listener);
~PackageWriterImpl();
status_t Init(const char* fileName);
status_t Init(const char* fileName, uint32 flags);
status_t AddEntry(const char* fileName, int fd = -1);
status_t Finish();
private:
struct Attribute;
struct PackageContentHandler;
struct Entry;
struct SubPathAdder;
struct HeapAttributeOffsetter;
typedef DoublyLinkedList<Entry> EntryList;
private:
status_t _Init(const char* fileName);
status_t _Init(const char* fileName, uint32 flags);
status_t _Finish();
status_t _RegisterEntry(const char* fileName, int fd);
@@ -58,6 +65,18 @@ private:
bool isImplicit);
status_t _CheckLicenses();
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 _MoveHeapChunk(off_t fromOffset, off_t toOffset,
off_t size);
void _AttributeRemoved(Attribute* attribute);
void _WriteTOC(hpkg_header& header);
int32 _WriteTOCSections(uint64& _stringsSize,
@@ -74,6 +93,8 @@ private:
void _AddEntry(int dirFD, Entry* entry,
const char* fileName, char* pathBuffer);
void _AddDirectoryChildren(Entry* entry, int fd,
char* pathBuffer);
Attribute* _AddAttribute(BHPKGAttributeID attributeID,
const AttributeValue& value);
@@ -105,6 +126,8 @@ private:
off_t fHeapOffset;
off_t fHeapEnd;
::BPrivate::RangeArray<off_t>* fHeapRangesToRemove;
void* fDataBuffer;
const size_t fDataBufferSize;
+11 -1
View File
@@ -147,7 +147,8 @@ protected:
typedef DoublyLinkedList<PackageAttribute> PackageAttributeList;
protected:
status_t Init(const char* fileName, const char* type);
status_t Init(const char* fileName, const char* type,
uint32 flags);
void RegisterPackageInfo(
PackageAttributeList& attributeList,
@@ -188,6 +189,7 @@ protected:
off_t offset);
inline int FD() const;
inline uint32 Flags() const;
inline const PackageAttributeList& PackageAttributes() const;
inline PackageAttributeList& PackageAttributes();
@@ -211,6 +213,7 @@ private:
private:
BErrorOutput* fErrorOutput;
const char* fFileName;
uint32 fFlags;
int fFD;
bool fFinished;
@@ -266,6 +269,13 @@ WriterImplBase::FD() const
}
inline uint32
WriterImplBase::Flags() const
{
return fFlags;
}
inline WriterImplBase::AbstractDataWriter*
WriterImplBase::DataWriter() const
{