input/Plugin: migrate open() from class Error to C++ exceptions
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
|
||||
#include <bzlib.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
class Bzip2ArchiveFile final : public ArchiveFile {
|
||||
@@ -74,9 +76,8 @@ public:
|
||||
visitor.VisitArchiveEntry(name.c_str());
|
||||
}
|
||||
|
||||
virtual InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond,
|
||||
Error &error) override;
|
||||
InputStream *OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond) override;
|
||||
};
|
||||
|
||||
class Bzip2InputStream final : public InputStream {
|
||||
@@ -93,13 +94,12 @@ public:
|
||||
Mutex &mutex, Cond &cond);
|
||||
~Bzip2InputStream();
|
||||
|
||||
bool Open(Error &error);
|
||||
|
||||
/* virtual methods from InputStream */
|
||||
bool IsEOF() override;
|
||||
size_t Read(void *ptr, size_t size, Error &error) override;
|
||||
|
||||
private:
|
||||
void Open();
|
||||
bool FillBuffer(Error &error);
|
||||
};
|
||||
|
||||
@@ -107,8 +107,8 @@ static constexpr Domain bz2_domain("bz2");
|
||||
|
||||
/* single archive handling allocation helpers */
|
||||
|
||||
inline bool
|
||||
Bzip2InputStream::Open(Error &error)
|
||||
inline void
|
||||
Bzip2InputStream::Open()
|
||||
{
|
||||
bzstream.bzalloc = nullptr;
|
||||
bzstream.bzfree = nullptr;
|
||||
@@ -118,27 +118,20 @@ Bzip2InputStream::Open(Error &error)
|
||||
bzstream.avail_in = 0;
|
||||
|
||||
int ret = BZ2_bzDecompressInit(&bzstream, 0, 0);
|
||||
if (ret != BZ_OK) {
|
||||
error.Set(bz2_domain, ret,
|
||||
"BZ2_bzDecompressInit() has failed");
|
||||
return false;
|
||||
}
|
||||
if (ret != BZ_OK)
|
||||
throw std::runtime_error("BZ2_bzDecompressInit() has failed");
|
||||
|
||||
SetReady();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* archive open && listing routine */
|
||||
|
||||
static ArchiveFile *
|
||||
bz2_open(Path pathname, Error &error)
|
||||
bz2_open(Path pathname, gcc_unused Error &error)
|
||||
{
|
||||
static Mutex mutex;
|
||||
static Cond cond;
|
||||
auto is = OpenLocalInputStream(pathname, mutex, cond, error);
|
||||
if (is == nullptr)
|
||||
return nullptr;
|
||||
|
||||
auto is = OpenLocalInputStream(pathname, mutex, cond);
|
||||
return new Bzip2ArchiveFile(pathname, std::move(is));
|
||||
}
|
||||
|
||||
@@ -150,6 +143,7 @@ Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context,
|
||||
:InputStream(_uri, _mutex, _cond),
|
||||
archive(&_context)
|
||||
{
|
||||
Open();
|
||||
archive->Ref();
|
||||
}
|
||||
|
||||
@@ -161,16 +155,9 @@ Bzip2InputStream::~Bzip2InputStream()
|
||||
|
||||
InputStream *
|
||||
Bzip2ArchiveFile::OpenStream(const char *path,
|
||||
Mutex &mutex, Cond &cond,
|
||||
Error &error)
|
||||
Mutex &mutex, Cond &cond)
|
||||
{
|
||||
Bzip2InputStream *bis = new Bzip2InputStream(*this, path, mutex, cond);
|
||||
if (!bis->Open(error)) {
|
||||
delete bis;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return bis;
|
||||
return new Bzip2InputStream(*this, path, mutex, cond);
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
Reference in New Issue
Block a user