aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/Bzip2ArchivePlugin.cxx4
-rw-r--r--src/archive/Iso9660ArchivePlugin.cxx81
-rw-r--r--src/archive/ZzipArchivePlugin.cxx2
3 files changed, 49 insertions, 38 deletions
diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx
index d1e6b51af..c2d312cd1 100644
--- a/src/archive/Bzip2ArchivePlugin.cxx
+++ b/src/archive/Bzip2ArchivePlugin.cxx
@@ -35,9 +35,7 @@
#include <bzlib.h>
-#include <stdint.h>
#include <stddef.h>
-#include <string.h>
#ifdef HAVE_OLDER_BZIP2
#define BZ2_bzDecompressInit bzDecompressInit
@@ -53,7 +51,7 @@ public:
Bzip2ArchiveFile(const char *path, InputStream *_is)
:ArchiveFile(bz2_archive_plugin),
- name(PathTraits::GetBaseUTF8(path)),
+ name(PathTraitsUTF8::GetBase(path)),
istream(_is) {
// remove .bz2 suffix
const size_t len = name.length();
diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx
index ad21d4a3d..c83e38b0d 100644
--- a/src/archive/Iso9660ArchivePlugin.cxx
+++ b/src/archive/Iso9660ArchivePlugin.cxx
@@ -32,7 +32,6 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include <cdio/cdio.h>
#include <cdio/iso9660.h>
#include <stdlib.h>
@@ -41,11 +40,11 @@
#define CEILING(x, y) ((x+(y-1))/y)
class Iso9660ArchiveFile final : public ArchiveFile {
-public:
RefCount ref;
iso9660_t *iso;
+public:
Iso9660ArchiveFile(iso9660_t *_iso)
:ArchiveFile(iso9660_archive_plugin), iso(_iso) {}
@@ -53,11 +52,19 @@ public:
iso9660_close(iso);
}
+ void Ref() {
+ ref.Increment();
+ }
+
void Unref() {
if (ref.Decrement())
delete this;
}
+ long SeekRead(void *ptr, lsn_t start, long int i_size) const {
+ return iso9660_iso_seek_read(iso, ptr, start, i_size);
+ }
+
void Visit(const char *path, ArchiveVisitor &visitor);
virtual void Close() override {
@@ -131,31 +138,35 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor)
/* single archive handling */
-struct Iso9660InputStream {
+class Iso9660InputStream {
InputStream base;
- Iso9660ArchiveFile *archive;
+ Iso9660ArchiveFile &archive;
iso9660_stat_t *statbuf;
- size_t max_blocks;
+public:
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri,
Mutex &mutex, Cond &cond,
iso9660_stat_t *_statbuf)
:base(iso9660_input_plugin, uri, mutex, cond),
- archive(&_archive), statbuf(_statbuf),
- max_blocks(CEILING(statbuf->size, ISO_BLOCKSIZE)) {
-
+ archive(_archive), statbuf(_statbuf) {
base.ready = true;
base.size = statbuf->size;
- archive->ref.Increment();
+ archive.Ref();
}
~Iso9660InputStream() {
free(statbuf);
- archive->Unref();
+ archive.Unref();
}
+
+ InputStream *Get() {
+ return &base;
+ }
+
+ size_t Read(void *ptr, size_t size, Error &error);
};
InputStream *
@@ -173,7 +184,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname,
Iso9660InputStream *iis =
new Iso9660InputStream(*this, pathname, mutex, cond,
statbuf);
- return &iis->base;
+ return iis->Get();
}
static void
@@ -184,45 +195,49 @@ iso9660_input_close(InputStream *is)
delete iis;
}
-
-static size_t
-iso9660_input_read(InputStream *is, void *ptr, size_t size,
- Error &error)
+inline size_t
+Iso9660InputStream::Read(void *ptr, size_t size, Error &error)
{
- Iso9660InputStream *iis = (Iso9660InputStream *)is;
int readed = 0;
int no_blocks, cur_block;
- size_t left_bytes = iis->statbuf->size - is->offset;
-
- size = (size * ISO_BLOCKSIZE) / ISO_BLOCKSIZE;
+ size_t left_bytes = statbuf->size - base.offset;
if (left_bytes < size) {
no_blocks = CEILING(left_bytes,ISO_BLOCKSIZE);
} else {
no_blocks = size / ISO_BLOCKSIZE;
}
- if (no_blocks > 0) {
- cur_block = is->offset / ISO_BLOCKSIZE;
+ if (no_blocks == 0)
+ return 0;
- readed = iso9660_iso_seek_read (iis->archive->iso, ptr,
- iis->statbuf->lsn + cur_block, no_blocks);
+ cur_block = base.offset / ISO_BLOCKSIZE;
- if (readed != no_blocks * ISO_BLOCKSIZE) {
- error.Format(iso9660_domain,
- "error reading ISO file at lsn %lu",
- (unsigned long)cur_block);
- return 0;
- }
- if (left_bytes < size) {
- readed = left_bytes;
- }
+ readed = archive.SeekRead(ptr, statbuf->lsn + cur_block,
+ no_blocks);
- is->offset += readed;
+ if (readed != no_blocks * ISO_BLOCKSIZE) {
+ error.Format(iso9660_domain,
+ "error reading ISO file at lsn %lu",
+ (unsigned long)cur_block);
+ return 0;
+ }
+ if (left_bytes < size) {
+ readed = left_bytes;
}
+
+ base.offset += readed;
return readed;
}
+static size_t
+iso9660_input_read(InputStream *is, void *ptr, size_t size,
+ Error &error)
+{
+ Iso9660InputStream *iis = (Iso9660InputStream *)is;
+ return iis->Read(ptr, size, error);
+}
+
static bool
iso9660_input_eof(InputStream *is)
{
diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx
index 973fe91dc..2ad4ea72e 100644
--- a/src/archive/ZzipArchivePlugin.cxx
+++ b/src/archive/ZzipArchivePlugin.cxx
@@ -34,8 +34,6 @@
#include <zzip/zzip.h>
-#include <string.h>
-
class ZzipArchiveFile final : public ArchiveFile {
public:
RefCount ref;