BPackageWriter: Add BPositionIO support
This commit is contained in:
parent
b916156a83
commit
44c4771163
@ -11,6 +11,9 @@
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
|
||||
|
||||
class BPositionIO;
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
@ -74,6 +77,9 @@ public:
|
||||
status_t Init(const char* fileName,
|
||||
const BPackageWriterParameters* parameters
|
||||
= NULL);
|
||||
status_t Init(BPositionIO* file, bool keepFile,
|
||||
const BPackageWriterParameters* parameters
|
||||
= NULL);
|
||||
status_t SetInstallPath(const char* installPath);
|
||||
void SetCheckLicenses(bool checkLicenses);
|
||||
status_t AddEntry(const char* fileName, int fd = -1);
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
|
||||
status_t Init(const char* fileName,
|
||||
const BPackageWriterParameters& parameters);
|
||||
status_t Init(BPositionIO* file, bool keepFile,
|
||||
const BPackageWriterParameters& parameters);
|
||||
status_t SetInstallPath(const char* installPath);
|
||||
void SetCheckLicenses(bool checkLicenses);
|
||||
status_t AddEntry(const char* fileName, int fd = -1);
|
||||
@ -67,7 +69,8 @@ private:
|
||||
typedef DoublyLinkedList<Entry> EntryList;
|
||||
|
||||
private:
|
||||
status_t _Init(const char* fileName,
|
||||
status_t _Init(BPositionIO* file, bool keepFile,
|
||||
const char* fileName,
|
||||
const BPackageWriterParameters& parameters);
|
||||
status_t _Finish();
|
||||
|
||||
|
@ -101,7 +101,8 @@ protected:
|
||||
typedef DoublyLinkedList<PackageAttribute> PackageAttributeList;
|
||||
|
||||
protected:
|
||||
status_t Init(const char* fileName,
|
||||
status_t Init(BPositionIO* file, bool keepFile,
|
||||
const char* fileName,
|
||||
const BPackageWriterParameters& parameters);
|
||||
status_t InitHeapReader(size_t headerSize);
|
||||
|
||||
@ -191,6 +192,7 @@ private:
|
||||
const char* fFileName;
|
||||
BPackageWriterParameters fParameters;
|
||||
BPositionIO* fFile;
|
||||
bool fOwnsFile;
|
||||
bool fFinished;
|
||||
|
||||
StringCache fPackageStringCache;
|
||||
|
@ -107,6 +107,20 @@ BPackageWriter::Init(const char* fileName,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageWriter::Init(BPositionIO* file, bool keepFile,
|
||||
const BPackageWriterParameters* parameters)
|
||||
{
|
||||
if (fImpl == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
BPackageWriterParameters defaultParameters;
|
||||
|
||||
return fImpl->Init(file, keepFile,
|
||||
parameters != NULL ? *parameters : defaultParameters);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BPackageWriter::SetInstallPath(const char* installPath)
|
||||
{
|
||||
|
@ -464,7 +464,22 @@ PackageWriterImpl::Init(const char* fileName,
|
||||
const BPackageWriterParameters& parameters)
|
||||
{
|
||||
try {
|
||||
return _Init(fileName, parameters);
|
||||
return _Init(NULL, false, fileName, parameters);
|
||||
} catch (status_t error) {
|
||||
return error;
|
||||
} catch (std::bad_alloc) {
|
||||
fListener->PrintError("Out of memory!\n");
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageWriterImpl::Init(BPositionIO* file, bool keepFile,
|
||||
const BPackageWriterParameters& parameters)
|
||||
{
|
||||
try {
|
||||
return _Init(file, keepFile, NULL, parameters);
|
||||
} catch (status_t error) {
|
||||
return error;
|
||||
} catch (std::bad_alloc) {
|
||||
@ -624,10 +639,10 @@ PackageWriterImpl::Recompress(PackageReaderImpl* reader)
|
||||
|
||||
|
||||
status_t
|
||||
PackageWriterImpl::_Init(const char* fileName,
|
||||
PackageWriterImpl::_Init(BPositionIO* file, bool keepFile, const char* fileName,
|
||||
const BPackageWriterParameters& parameters)
|
||||
{
|
||||
status_t result = inherited::Init(fileName, parameters);
|
||||
status_t result = inherited::Init(file, keepFile, fileName, parameters);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
|
@ -264,7 +264,8 @@ RepositoryWriterImpl::Finish()
|
||||
status_t
|
||||
RepositoryWriterImpl::_Init(const char* fileName)
|
||||
{
|
||||
status_t error = inherited::Init(fileName, BPackageWriterParameters());
|
||||
status_t error = inherited::Init(NULL, false, fileName,
|
||||
BPackageWriterParameters());
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
|
@ -228,6 +228,7 @@ WriterImplBase::WriterImplBase(const char* fileType, BErrorOutput* errorOutput)
|
||||
fFileName(NULL),
|
||||
fParameters(),
|
||||
fFile(NULL),
|
||||
fOwnsFile(false),
|
||||
fFinished(false)
|
||||
{
|
||||
}
|
||||
@ -241,7 +242,8 @@ WriterImplBase::~WriterImplBase()
|
||||
delete fDecompressionAlgorithm;
|
||||
delete fDecompressionParameters;
|
||||
|
||||
delete fFile;
|
||||
if (fOwnsFile)
|
||||
delete fFile;
|
||||
|
||||
if (!fFinished && fFileName != NULL
|
||||
&& (Flags() & B_HPKG_WRITER_UPDATE_PACKAGE) == 0) {
|
||||
@ -251,7 +253,7 @@ WriterImplBase::~WriterImplBase()
|
||||
|
||||
|
||||
status_t
|
||||
WriterImplBase::Init(const char* fileName,
|
||||
WriterImplBase::Init(BPositionIO* file, bool keepFile, const char* fileName,
|
||||
const BPackageWriterParameters& parameters)
|
||||
{
|
||||
fParameters = parameters;
|
||||
@ -259,21 +261,31 @@ WriterImplBase::Init(const char* fileName,
|
||||
if (fPackageStringCache.Init() != B_OK)
|
||||
throw std::bad_alloc();
|
||||
|
||||
// open file (don't truncate in update mode)
|
||||
int openMode = O_RDWR;
|
||||
if ((Flags() & B_HPKG_WRITER_UPDATE_PACKAGE) == 0)
|
||||
openMode |= O_CREAT | O_TRUNC;
|
||||
if (file == NULL) {
|
||||
if (fileName == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
BFile* file = new BFile;
|
||||
status_t error = file->SetTo(fileName, openMode);
|
||||
if (error != B_OK) {
|
||||
fErrorOutput->PrintError("Failed to open %s file \"%s\": %s\n",
|
||||
fFileType, fileName, strerror(errno));
|
||||
delete file;
|
||||
return error;
|
||||
// open file (don't truncate in update mode)
|
||||
int openMode = O_RDWR;
|
||||
if ((parameters.Flags() & B_HPKG_WRITER_UPDATE_PACKAGE) == 0)
|
||||
openMode |= O_CREAT | O_TRUNC;
|
||||
|
||||
BFile* newFile = new BFile;
|
||||
status_t error = newFile->SetTo(fileName, openMode);
|
||||
if (error != B_OK) {
|
||||
fErrorOutput->PrintError("Failed to open %s file \"%s\": %s\n",
|
||||
fFileType, fileName, strerror(errno));
|
||||
delete newFile;
|
||||
return error;
|
||||
}
|
||||
|
||||
fFile = newFile;
|
||||
fOwnsFile = true;
|
||||
} else {
|
||||
fFile = file;
|
||||
fOwnsFile = keepFile;
|
||||
}
|
||||
|
||||
fFile = file;
|
||||
fFileName = fileName;
|
||||
|
||||
return B_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user