Remove BPackageKit::[...]::AbstractDataWriter and friends
* FDDataWriter and ZlibDataWriter weren't used anymore. * AbstractDataWriter was implemented only by PackageFileHeapWriter, which was only used by WriterImplBase. * Add a PackageFileHeapWriter::AddDataThrows() which has semantics equivalent to the previously inherited WriteDataThrows().
This commit is contained in:
parent
32832cbe47
commit
84297881bb
@ -1 +0,0 @@
|
||||
#include <../private/package/hpkg/DataWriters.h>
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
|
||||
#define _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
|
||||
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
|
||||
class BErrorOutput;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class AbstractDataWriter {
|
||||
public:
|
||||
AbstractDataWriter();
|
||||
virtual ~AbstractDataWriter();
|
||||
|
||||
uint64 BytesWritten() const
|
||||
{ return fBytesWritten; }
|
||||
|
||||
virtual status_t WriteDataNoThrow(const void* buffer,
|
||||
size_t size) = 0;
|
||||
|
||||
void WriteDataThrows(const void* buffer,
|
||||
size_t size);
|
||||
|
||||
protected:
|
||||
uint64 fBytesWritten;
|
||||
};
|
||||
|
||||
|
||||
class FDDataWriter : public AbstractDataWriter {
|
||||
public:
|
||||
FDDataWriter(int fd, off_t offset,
|
||||
BErrorOutput* errorOutput);
|
||||
|
||||
virtual status_t WriteDataNoThrow(const void* buffer,
|
||||
size_t size);
|
||||
|
||||
off_t Offset() const
|
||||
{ return fOffset; }
|
||||
|
||||
private:
|
||||
int fFD;
|
||||
off_t fOffset;
|
||||
BErrorOutput* fErrorOutput;
|
||||
};
|
||||
|
||||
|
||||
class ZlibDataWriter : public AbstractDataWriter, private BDataIO {
|
||||
public:
|
||||
ZlibDataWriter(AbstractDataWriter* dataWriter);
|
||||
|
||||
void Init();
|
||||
void Finish();
|
||||
|
||||
virtual status_t WriteDataNoThrow(const void* buffer,
|
||||
size_t size);
|
||||
|
||||
private:
|
||||
// BDataIO
|
||||
virtual ssize_t Write(const void* buffer, size_t size);
|
||||
|
||||
private:
|
||||
AbstractDataWriter* fDataWriter;
|
||||
ZlibCompressor fCompressor;
|
||||
};
|
||||
|
||||
|
||||
// inline implementations
|
||||
|
||||
|
||||
inline void
|
||||
AbstractDataWriter::WriteDataThrows(const void* buffer, size_t size)
|
||||
{
|
||||
status_t error = WriteDataNoThrow(buffer, size);
|
||||
if (error != B_OK)
|
||||
throw status_t(error);
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _PACKAGE__HPKG__PRIVATE__DATA_WRITERS_H_
|
@ -7,7 +7,6 @@
|
||||
|
||||
|
||||
#include <Array.h>
|
||||
#include <package/hpkg/DataWriters.h>
|
||||
#include <package/hpkg/PackageFileHeapAccessorBase.h>
|
||||
|
||||
|
||||
@ -31,8 +30,7 @@ namespace BPrivate {
|
||||
class PackageFileHeapReader;
|
||||
|
||||
|
||||
class PackageFileHeapWriter : public PackageFileHeapAccessorBase,
|
||||
private AbstractDataWriter {
|
||||
class PackageFileHeapWriter : public PackageFileHeapAccessorBase {
|
||||
public:
|
||||
PackageFileHeapWriter(BErrorOutput* errorOutput,
|
||||
int fd, off_t heapOffset,
|
||||
@ -42,11 +40,9 @@ public:
|
||||
void Init();
|
||||
void Reinit(PackageFileHeapReader* heapReader);
|
||||
|
||||
AbstractDataWriter* DataWriter()
|
||||
{ return this; }
|
||||
|
||||
status_t AddData(BDataReader& dataReader, off_t size,
|
||||
uint64& _offset);
|
||||
void AddDataThrows(const void* buffer, size_t size);
|
||||
void RemoveDataRanges(
|
||||
const ::BPrivate::RangeArray<uint64>&
|
||||
ranges);
|
||||
@ -58,11 +54,6 @@ protected:
|
||||
void* compressedDataBuffer,
|
||||
void* uncompressedDataBuffer);
|
||||
|
||||
private:
|
||||
// AbstractDataWriter
|
||||
virtual status_t WriteDataNoThrow(const void* buffer,
|
||||
size_t size);
|
||||
|
||||
private:
|
||||
struct Chunk;
|
||||
struct ChunkSegment;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||
|
||||
#include <package/hpkg/DataWriters.h>
|
||||
#include <package/hpkg/PackageFileHeapWriter.h>
|
||||
#include <package/hpkg/PackageWriter.h>
|
||||
#include <package/hpkg/Strings.h>
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
@ -30,9 +30,6 @@ class BErrorOutput;
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class AbstractDataWriter;
|
||||
class PackageFileHeapWriter;
|
||||
|
||||
struct hpkg_header;
|
||||
|
||||
|
||||
@ -183,8 +180,6 @@ private:
|
||||
int fFD;
|
||||
bool fFinished;
|
||||
|
||||
AbstractDataWriter* fDataWriter;
|
||||
|
||||
StringCache fPackageStringCache;
|
||||
PackageAttributeList fPackageAttributes;
|
||||
};
|
||||
@ -208,7 +203,7 @@ WriterImplBase::WriteString(const char* string)
|
||||
inline void
|
||||
WriterImplBase::WriteBuffer(const void* data, size_t size)
|
||||
{
|
||||
fDataWriter->WriteDataThrows(data, size);
|
||||
fHeapWriter->AddDataThrows(data, size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,6 @@ HPKG_SOURCES =
|
||||
BufferPool.cpp
|
||||
PoolBuffer.cpp
|
||||
DataReader.cpp
|
||||
DataWriters.cpp
|
||||
ErrorOutput.cpp
|
||||
FDDataReader.cpp
|
||||
GlobalWritableFileInfo.cpp
|
||||
|
@ -16,7 +16,6 @@ HPKG_SOURCES =
|
||||
BufferPool.cpp
|
||||
CommitTransactionResult.cpp
|
||||
DataReader.cpp
|
||||
DataWriters.cpp
|
||||
ErrorOutput.cpp
|
||||
FDDataReader.cpp
|
||||
GlobalWritableFileInfo.cpp
|
||||
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <package/hpkg/DataWriters.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <package/hpkg/ErrorOutput.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
namespace BHPKG {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// #pragma mark - AbstractDataWriter
|
||||
|
||||
|
||||
AbstractDataWriter::AbstractDataWriter()
|
||||
:
|
||||
fBytesWritten(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractDataWriter::~AbstractDataWriter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - FDDataWriter
|
||||
|
||||
|
||||
FDDataWriter::FDDataWriter(int fd, off_t offset, BErrorOutput* errorOutput)
|
||||
:
|
||||
fFD(fd),
|
||||
fOffset(offset),
|
||||
fErrorOutput(errorOutput)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
FDDataWriter::WriteDataNoThrow(const void* buffer, size_t size)
|
||||
{
|
||||
ssize_t bytesWritten = pwrite(fFD, buffer, size, fOffset);
|
||||
if (bytesWritten < 0) {
|
||||
fErrorOutput->PrintError(
|
||||
"WriteDataNoThrow(%p, %lu) failed to write data: %s\n", buffer,
|
||||
size, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if ((size_t)bytesWritten != size) {
|
||||
fErrorOutput->PrintError(
|
||||
"WriteDataNoThrow(%p, %lu) failed to write all data\n", buffer,
|
||||
size);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
fOffset += size;
|
||||
fBytesWritten += size;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - ZlibDataWriter
|
||||
|
||||
|
||||
ZlibDataWriter::ZlibDataWriter(AbstractDataWriter* dataWriter)
|
||||
:
|
||||
fDataWriter(dataWriter),
|
||||
fCompressor(this)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ZlibDataWriter::Init()
|
||||
{
|
||||
status_t error = fCompressor.Init();
|
||||
if (error != B_OK)
|
||||
throw status_t(error);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ZlibDataWriter::Finish()
|
||||
{
|
||||
status_t error = fCompressor.Finish();
|
||||
if (error != B_OK)
|
||||
throw status_t(error);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ZlibDataWriter::WriteDataNoThrow(const void* buffer,
|
||||
size_t size)
|
||||
{
|
||||
status_t error = fCompressor.CompressNext(buffer, size);
|
||||
if (error == B_OK)
|
||||
fBytesWritten += size;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
ZlibDataWriter::Write(const void* buffer, size_t size)
|
||||
{
|
||||
status_t error = fDataWriter->WriteDataNoThrow(buffer, size);
|
||||
return error == B_OK ? (ssize_t)size : (ssize_t)error;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
} // namespace BHPKG
|
||||
|
||||
} // namespace BPackageKit
|
@ -19,6 +19,7 @@
|
||||
#include <AutoDeleter.h>
|
||||
#include <package/hpkg/DataReader.h>
|
||||
#include <package/hpkg/PackageFileHeapReader.h>
|
||||
#include <package/hpkg/ZlibCompressor.h>
|
||||
#include <RangeArray.h>
|
||||
|
||||
|
||||
@ -284,6 +285,17 @@ PackageFileHeapWriter::AddData(BDataReader& dataReader, off_t size,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageFileHeapWriter::AddDataThrows(const void* buffer, size_t size)
|
||||
{
|
||||
BBufferDataReader reader(buffer, size);
|
||||
uint64 dummyOffset;
|
||||
status_t error = AddData(reader, size, dummyOffset);
|
||||
if (error != B_OK)
|
||||
throw status_t(error);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageFileHeapWriter::RemoveDataRanges(
|
||||
const ::BPrivate::RangeArray<uint64>& ranges)
|
||||
@ -400,7 +412,7 @@ PackageFileHeapWriter::RemoveDataRanges(
|
||||
}
|
||||
|
||||
// add chunk data
|
||||
WriteDataThrows((uint8*)uncompressedData + segment.toKeepOffset,
|
||||
AddDataThrows((uint8*)uncompressedData + segment.toKeepOffset,
|
||||
segment.toKeepSize);
|
||||
|
||||
chunkBuffer.CurrentSegmentDone();
|
||||
@ -476,15 +488,6 @@ PackageFileHeapWriter::ReadAndDecompressChunk(size_t chunkIndex,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PackageFileHeapWriter::WriteDataNoThrow(const void* buffer, size_t size)
|
||||
{
|
||||
BBufferDataReader reader(buffer, size);
|
||||
uint64 dummyOffset;
|
||||
return AddData(reader, size, dummyOffset);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageFileHeapWriter::_Uninit()
|
||||
{
|
||||
|
@ -222,8 +222,7 @@ WriterImplBase::WriterImplBase(const char* fileType, BErrorOutput* errorOutput)
|
||||
fFileName(NULL),
|
||||
fParameters(),
|
||||
fFD(-1),
|
||||
fFinished(false),
|
||||
fDataWriter(NULL)
|
||||
fFinished(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -269,7 +268,6 @@ WriterImplBase::Init(const char* fileName, size_t headerSize,
|
||||
fHeapWriter = new PackageFileHeapWriter(fErrorOutput, FD(), headerSize,
|
||||
fParameters.CompressionLevel());
|
||||
fHeapWriter->Init();
|
||||
fDataWriter = fHeapWriter->DataWriter();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@ -649,7 +647,7 @@ WriterImplBase::WriteAttributeValue(const AttributeValue& value, uint8 encoding)
|
||||
if (encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP)
|
||||
WriteUnsignedLEB128(value.data.offset);
|
||||
else
|
||||
fDataWriter->WriteDataThrows(value.data.raw, value.data.size);
|
||||
fHeapWriter->AddDataThrows(value.data.raw, value.data.size);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -672,7 +670,7 @@ WriterImplBase::WriteUnsignedLEB128(uint64 value)
|
||||
bytes[count++] = byte | (value != 0 ? 0x80 : 0);
|
||||
} while (value != 0);
|
||||
|
||||
fDataWriter->WriteDataThrows(bytes, count);
|
||||
fHeapWriter->AddDataThrows(bytes, count);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user