Commit Graph

80 Commits

Author SHA1 Message Date
Alexander von Gluck IV 6c331fc7e1 kit/package: Error on short file read
* It's safe to assume that if the file is shorter than
  the provided header, things will go poorly.
* Avoids a random vauge ReadBuffer error.
* This doesn't fix #15230, but makes the issue clearer.

Change-Id: I3471e6de384a0c9be94049ad891c01be980f7846
Reviewed-on: https://review.haiku-os.org/c/1679
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
2019-08-05 15:07:24 +00:00
Murai Takashi 92b072972b Packagekit: Fix -Wmismatched-tags
Replace 'class' with 'struct', since they are already defined as 'struct'
in PackageInfoAttributeValue.h
Pointed by clang [-Wmismatched-tags]

Change-Id: I094d32c3444fe4299a3afe0872ade296f92debf9
Reviewed-on: https://review.haiku-os.org/471
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2018-08-19 20:36:25 +00:00
Ingo Weinhold e1e6c12480 BPackageWriter::Recompress(): Change param to BPositionIO*
Besides that this is a nicer interface, it allows us to get a the HPKG
header as a side effect of initializing the reader, thus preventing
seeking backward in the file. This makes "package recompress - <file>"
work.
2014-07-13 17:57:57 +02:00
Ingo Weinhold 43a6b92c64 PackageReaderImpl: Delay reading sections until ParseContent() 2014-07-13 17:57:56 +02:00
Ingo Weinhold 1606450b32 ReaderImplBase::Init(): Make file size check optional
If the file doesn't support GetSize(), skip the header total size file
size check.
2014-07-13 17:57:56 +02:00
Ingo Weinhold 44c4771163 BPackageWriter: Add BPositionIO support 2014-07-13 17:57:55 +02:00
Ingo Weinhold 8f5130edfa package kit: Actually add support for B_HPKG_COMPRESSION_NONE
Until now we always declared in the HPKG header that the package file is
zlib compressed. For uncompressed files we would just store all
individual chunks uncompressed. Now we handle completely uncompressed
files slightly differently: We don't write the redundant chunk size
table anymore. The size savings are minor, but it makes the uncompressed
format read-streamable which may be handy.
2014-07-12 23:12:21 +02:00
Ingo Weinhold e527b79631 Switch package file accessor classes to use BPositionIO
* PackageFileHeap{Reader,Writer} as well as Package{Reader,Writer} and
  their implementation and super classes do now internally use a
  BPositionIO instead of a FD to access the package file. This provides
  more flexibility needed for features to come.
* BPackageReader has already grown a new Init() version with a
  BPositionIO* parameter.
2014-07-12 15:40:22 +02:00
Ingo Weinhold cdfeba5a1e BPackageWriter: Add Recompress()
Allows rewriting an existing package file with a different compression.
2014-07-08 22:00:35 +02:00
Ingo Weinhold b3263ad3e1 Switch package kit to BZlibCompressionAlgorithm
... and remove the Zlib{Compressor,Decompressor} API.
2014-06-30 21:55:41 +02:00
Ingo Weinhold 6a89a36aa0 Move package kit Zlib* classes to support kit
Also move to B* namespace and no longer expose the zlib dependency in
the headers.
2014-06-30 21:55:41 +02:00
Ingo Weinhold 0dab9e5cb4 package kit: ReaderImplBase: Remove superfluous scratch buffer 2014-06-30 21:51:16 +02:00
Ingo Weinhold 0a62e01902 PackageWriterImpl: Remove superfluous method 2014-06-30 21:51:16 +02:00
Ingo Weinhold 84297881bb 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().
2014-06-23 22:58:15 +02:00
Ingo Weinhold 32832cbe47 Remove BPackageKit::BDataOutput
Use BDataIO instead.
2014-06-23 22:58:15 +02:00
Ingo Weinhold d2d1af830b Revert "Move ZlibDecompressor to libshared"
This reverts commit 9af2105d36.

Conflicts:
	src/kits/package/Jamfile
2014-06-18 22:13:39 +02:00
Ingo Weinhold d5660e67af Revert "build fix follow up on status_t/ssize_t changes."
This reverts commit 7202cfb455.
2014-06-18 22:13:38 +02:00
Jérôme Duval 7202cfb455 build fix follow up on status_t/ssize_t changes.
* added a TODO in packagefs.
2014-02-11 18:26:41 +01:00
Adrien Destugues 9af2105d36 Move ZlibDecompressor to libshared
* This will be used to implement compressed http streams
* Remove the custom BDataOutput class, and use BDataIO instead, for
easier integration with existing code.
2014-02-11 12:06:38 +01:00
Ingo Weinhold 3f40dcb6b4 PackageWriterImpl::_AttributeRemoved(): Update string cache
When removing a string attribute, decrement the referenced string's
usage count in the string cache. This fixes the potentially incorrect
usage counts in update mode. Not a serious problem, but it could lead
to only singly (or no longer) used strings to be written to the string
subsection instead of encoding them inline and thus to slightly greater
file sizes.
2013-10-25 22:54:44 +02:00
Ingo Weinhold b8f713e904 PackageReaderImpl: Add public TOC section accessor 2013-10-25 22:54:44 +02:00
Ingo Weinhold e07b8bd2df package kit: ReaderImplBase: Add public attrs section accessor 2013-10-25 22:54:43 +02:00
Oliver Tappe 0a345af77e Separate notification from deletion in repository-handlers.
* Add NotifyDone() to all repository-attribute handlers and invoke that
  to notify any listeners.
* Unify deletion to a single implementation of Delete() in the base
  class. Before, the root handler for a repository didn't do that, but
  just triggered the notification.
2013-09-18 21:16:13 +02:00
Oliver Tappe 50ae264dad Add support for adding a package-info to BRepositoryWriter. 2013-09-18 12:05:34 +02:00
Ingo Weinhold e85334022e Repository file format: group attributes of a package
* Introduce new package attribute B_HPKG_ATTRIBUTE_ID_PACKAGE (valid
  only in a repository file) to group the attributes belonging to a
  package.
* BRepositoryContentHandler:
  - No longer derive from BPackageContentHandler.
  - Add hooks HandlePackage() and HandlePackageDone() that bracket the
    attributes for a package. This is more explicit and robust than
    handlers having to guess when one package ended and the next began.
* BRepositoryCache: Make use of BPackageInfoContentHandler. No need to
  duplicate the code for reading a package info from package info
  attributes.
2013-07-04 19:20:14 +02:00
Ingo Weinhold 695a1b248a repository writer: fix use of incorrect header size
The header size of the package file header was used, which resulted in
broken repository files.
2013-07-04 16:37:24 +02:00
Ingo Weinhold 4489c88b61 hpkg format: Generalize user/global settings file attributes
* For all identifiers: Rename global settings file to global writable
  file. We want to use the respective attribute also for other writable
  files, not only settings files.
* User settings file/global writable file info/attribute: Add
  isDirectory property/child attribute. This allows declaring global/
  user settings directories associated with the package.
2013-06-06 00:17:02 +02:00
Ingo Weinhold a3e070a7ff WriterImplBase: Add _AddStringAttributeList()
... and simplify some code by using it.
2013-05-25 01:12:38 +02:00
Ingo Weinhold 0f4e11e75c hpkg format: Add attributes for declaring users and groups 2013-05-25 01:12:37 +02:00
Ingo Weinhold 79d5ddb77b ReaderImplBase: Verify that the attribute type matches
... the one expected for the respective attribute. Before it was
possible that e.g. a uint was read and then interpreted as a
const char*, if a string was expected for that attribute.
2013-05-25 01:12:35 +02:00
Ingo Weinhold fe707a23fc hpkg format: Add attributes for declaring settings files
Global and user settings files can be declared. For global ones an
update policy can be specified. If not specified, the settings file is
not included in the package, but created by the program (or user) later.
If an update type is specified, it defines what to do with the settings
file when updating the package to a newer version.

User settings files are never included in the package; they are always
created by the program or the user. If the package contains a template/
default settings file, it can be declared, but for informative purposes
only.
2013-05-25 01:12:34 +02:00
Ingo Weinhold 5497f08e5e hpkg attribute tags: use 7 bits for attribute ID
ATM the 6 bits suffice, but there isn't that much headroom.
2013-05-25 01:12:34 +02:00
Ingo Weinhold 47039b852e Package/repository file format: Add a minor version header field
* Add minor_version to hpkg_header and hpkg_repo_header and make
  heap_compression uint16.
* If the minor version of a package/repository file is greater than the
  current one unknown attributes are ignored without error. This allows
  introducing new harmless attributes without making the resulting files
  unreadable for older package kit versions.
2013-05-25 01:12:33 +02:00
Ingo Weinhold 46122852f1 packagefs: Add caching for the package file heap reader
* ReaderImplBase:
  - Add virtual CreateCachedHeapReader() which can create a cached
    reader based on the given heap reader.
  - Rename HeapReader() to RawHeapReader() and add HeapReader() for the
    cached heap reader.
  - Add DetachHeapReader() to allow a clients to remove the heap
    reader(s) after deleting the ReaderImplBase object.
* packagefs:
  - Add CachedDataReader class, which wraps a given
    BAbstractBufferedDataReader and provides caching for it using a
    VMCache. The implementation is based on the IOCache implementation.
  - Use CachedDataReader to wrap the heap reader. For file data that
    means they are cached twice -- in the heap reader cache and in the
    file cache -- but due to the heap reader using a VMCache as well,
    the pages will be recycled automatically anyway. For attribute data
    the cache should be very helpful, since they weren't cached at all
    before.
2013-05-25 01:12:32 +02:00
Ingo Weinhold d59e0feb59 package: Suppress version mismatch errors where V1 is supported
* Add flags parameter to Init() of BPackageReader and friends.
* Introduce flag B_HPKG_READER_DONT_PRINT_VERSION_MISMATCH_MESSAGE and
  don't print a version mismatch error when given.
* package extract/list: Use the new flag.
2013-05-25 01:12:31 +02:00
Ingo Weinhold 521545f7fb Add padding in HPKG/HPKR headers
... so that the different alignment on 32 and 64 bit machines doesn't
change the layout.
2013-05-25 01:12:28 +02:00
Ingo Weinhold d03ac965a2 ReaderImplBase: Fix gcc 4 build 2013-05-25 01:12:28 +02:00
Ingo Weinhold b05413ed78 PackageFileHeapWriter: Fix update case
* Pull _UnwriteLastPartialChunk() out of Reinit() for reuse.
* _UnwriteLastPartialChunk(): fPendingDataSize wasn't set.
* _PushChunks(): Some simplifications for clarity.
* ChunkBuffer/RemoveDataRanges(): Use data reading and decompression
  methods provided by our base class instead of duplicating the
  implementation.
* RemoveDataRanges():
  - _FlushPendingData() before starting, so we don't ignore the pending
    data and _UnwriteLastPartialChunk() when done, so a partial chunk
    is read back into the pending data buffer.
  - fUncompressedHeapSize wasn't reset before the main processing loop,
    thus resulting in an erroneous size later on.
2013-05-25 01:12:27 +02:00
Ingo Weinhold 520a7a76c7 PackageFileHeapAccessorBase: small refactoring
* Pull method DecompressChunkData() out of ReadAndDecompressChunkData()
  for potential reuse.
* Also fix/improve some error output strings.
2013-05-25 01:12:27 +02:00
Ingo Weinhold 796343ed73 Allow specifying the compression level for package creation
* Introduce BPackageWriterParameters which comprises all parameters
  for package creation, currently flags and compression level. Such an
  object can be passed to BPackageWriter::Init() and is passed on to
  PackageWriterImpl and WriterImplBase.
* PackageFileHeapWriter: Add compressionLevel property and pass the
  value on to ZlibCompressor.
* package add/create: Add options -0 ... -9 to specify the compression
  level to be used.
2013-05-25 01:12:26 +02:00
Ingo Weinhold 18b19ba49d ZlibCompressor: Allow setting the compression level 2013-05-25 01:12:26 +02:00
Ingo Weinhold 1f633814fa hpkg format: compress the whole heap
Instead of handling compression for individual file/attribute data we
do now compress the whole heap where they are stored. This
significantly improves compression ratios. We still divide the
uncompressed data into 64 KiB chunks and use a chunk offset array for
the compressed chunks to allow for quick random access without too much
overhead. The tradeoff is a limited possible compression ratio -- i.e.
we won't be as good as tar.gz (though surprisingly with my test
archives we did better than zip).

The other package file sections (package attributes and TOC) are no
longer compressed individually. Their uncompressed data are simply
pushed onto the heap where the usual compression strategy applies. To
simplify things the repository format has been changed in the same
manner although it doesn't otherwise use the heap, since it only stores
meta data.

Due to the data compression having been exposed in public and private
API, this change touches a lot of package kit using code, including
packagefs and the boot loader packagefs support. The latter two haven't
been tested yet. Moreover packagefs needs a new kind of cache so we
avoid re-reading the same heap chunk for two different data items it
contains.
2013-05-25 01:12:25 +02:00
Ingo Weinhold 0ee1651856 Rename BBlockBufferCache and friends to *Pool*
Also move BBlockBufferPoolNoLock into BHPKG namespace with the other
classes. Not sure why it wasn't there before.
2013-05-25 01:12:25 +02:00
Ingo Weinhold 7575abbca2 Clone read support functionality for HPKG format version 1
It uses sub-namespace BPackage::BHPKG::V1. Unlike the one for the
current format version, the V1 version of BPackageInfoContentHandler
lives in BHPKG(::V1) sub-namespace and is private.
2013-05-25 01:12:22 +02:00
Ingo Weinhold 171fd58c4b package kit: some fixes for multi-version support
* Use enums/constants/functions instead of preprocessor macros.
* Missing include in PackageInfoAttributeValue.h.
* PackageReaderImpl::Init(): Check version before header size and
  return B_MISMATCHED_VALUES instead of B_BAD_DATA, if the version
  doesn't match. This allows callers to determine the condition and
  try a reader for a different version. A more flexible interface for
  that case would be nice, but since we want to support the old package
  version only temporarily, the current solution should be good enough.
2013-05-25 01:12:21 +02:00
Ingo Weinhold f19957b8e5 Add a package info "install-path" attribute
The attribute is intended for simplifying package building. The
package's install path will be used for the package's .self package
symlink, allowing installation to a temporary directory when building
the package.
2011-07-17 16:55:14 +02:00
Ingo Weinhold d7227dfa9e BPackageWriter: Add SetCheckLicenses()
The default is still "true", but now it is possible to disable the
license check.
2011-07-17 16:55:14 +02:00
Ingo Weinhold 6f785748aa Write uncompressed package file TOC, if necessary 2011-07-17 16:54:57 +02:00
Ingo Weinhold 327b38d69c 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.
2011-07-17 16:54:56 +02:00
Ingo Weinhold 7b6bcdb146 Write uncompressed package attributes if necessary
When compression doesn't save space, using it nonetheless results in a
file that the reader complains about. So we fall back to writing an
uncompressed package attributes section in such a case.

The same still needs to be done for the TOC section.
2011-07-17 16:54:56 +02:00