diff --git a/headers/build/private/package/hpkg/DataWriters.h b/headers/build/private/package/hpkg/DataWriters.h deleted file mode 100644 index 1f9f8962ca..0000000000 --- a/headers/build/private/package/hpkg/DataWriters.h +++ /dev/null @@ -1 +0,0 @@ -#include <../private/package/hpkg/DataWriters.h> diff --git a/headers/private/package/hpkg/DataWriters.h b/headers/private/package/hpkg/DataWriters.h deleted file mode 100644 index 9ff394dd36..0000000000 --- a/headers/private/package/hpkg/DataWriters.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2011, Oliver Tappe - * 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 -#include - - -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_ diff --git a/headers/private/package/hpkg/PackageFileHeapWriter.h b/headers/private/package/hpkg/PackageFileHeapWriter.h index 36db523d82..089a049503 100644 --- a/headers/private/package/hpkg/PackageFileHeapWriter.h +++ b/headers/private/package/hpkg/PackageFileHeapWriter.h @@ -7,7 +7,6 @@ #include -#include #include @@ -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& 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; diff --git a/headers/private/package/hpkg/WriterImplBase.h b/headers/private/package/hpkg/WriterImplBase.h index 28496d19b8..907932cbdf 100644 --- a/headers/private/package/hpkg/WriterImplBase.h +++ b/headers/private/package/hpkg/WriterImplBase.h @@ -10,7 +10,7 @@ #include -#include +#include #include #include #include @@ -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); } diff --git a/src/build/libpackage/Jamfile b/src/build/libpackage/Jamfile index 54d95fc3d3..953bab1d78 100644 --- a/src/build/libpackage/Jamfile +++ b/src/build/libpackage/Jamfile @@ -36,7 +36,6 @@ HPKG_SOURCES = BufferPool.cpp PoolBuffer.cpp DataReader.cpp - DataWriters.cpp ErrorOutput.cpp FDDataReader.cpp GlobalWritableFileInfo.cpp diff --git a/src/kits/package/Jamfile b/src/kits/package/Jamfile index 5857263f7a..0a55b7c690 100644 --- a/src/kits/package/Jamfile +++ b/src/kits/package/Jamfile @@ -16,7 +16,6 @@ HPKG_SOURCES = BufferPool.cpp CommitTransactionResult.cpp DataReader.cpp - DataWriters.cpp ErrorOutput.cpp FDDataReader.cpp GlobalWritableFileInfo.cpp diff --git a/src/kits/package/hpkg/DataWriters.cpp b/src/kits/package/hpkg/DataWriters.cpp deleted file mode 100644 index fdf4bdc071..0000000000 --- a/src/kits/package/hpkg/DataWriters.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2011, Oliver Tappe - * Copyright 2013-2014, Ingo Weinhold, ingo_weinhold@gmx.de. - * Distributed under the terms of the MIT License. - */ - - -#include - -#include -#include -#include - -#include - - -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 diff --git a/src/kits/package/hpkg/PackageFileHeapWriter.cpp b/src/kits/package/hpkg/PackageFileHeapWriter.cpp index 38b1c9cec4..f112f2e462 100644 --- a/src/kits/package/hpkg/PackageFileHeapWriter.cpp +++ b/src/kits/package/hpkg/PackageFileHeapWriter.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -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& 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() { diff --git a/src/kits/package/hpkg/WriterImplBase.cpp b/src/kits/package/hpkg/WriterImplBase.cpp index 0fd01e3509..7df54168f6 100644 --- a/src/kits/package/hpkg/WriterImplBase.cpp +++ b/src/kits/package/hpkg/WriterImplBase.cpp @@ -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); }