archive/Plugin: migrate open() from class Error to C++ exceptions

This commit is contained in:
Max Kellermann
2016-09-09 18:34:55 +02:00
parent fc7d3f64c0
commit 220d9528a3
9 changed files with 27 additions and 49 deletions

View File

@@ -22,7 +22,6 @@
class Mutex;
class Cond;
class Error;
struct ArchivePlugin;
class ArchiveVisitor;
class InputStream;

View File

@@ -20,20 +20,15 @@
#include "config.h"
#include "ArchivePlugin.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include <assert.h>
ArchiveFile *
archive_file_open(const ArchivePlugin *plugin, Path path,
Error &error)
archive_file_open(const ArchivePlugin *plugin, Path path)
{
assert(plugin != nullptr);
assert(plugin->open != nullptr);
assert(!path.IsNull());
ArchiveFile *file = plugin->open(path, error);
assert((file == nullptr) == error.IsDefined());
return file;
return plugin->open(path);
}

View File

@@ -22,7 +22,6 @@
class ArchiveFile;
class Path;
class Error;
struct ArchivePlugin {
const char *name;
@@ -43,9 +42,10 @@ struct ArchivePlugin {
/**
* tryes to open archive file and associates handle with archive
* returns pointer to handle used is all operations with this archive
* or nullptr when opening fails
*
* Throws std::runtime_error on error.
*/
ArchiveFile *(*open)(Path path_fs, Error &error);
ArchiveFile *(*open)(Path path_fs);
/**
* suffixes handled by this plugin.
@@ -55,7 +55,6 @@ struct ArchivePlugin {
};
ArchiveFile *
archive_file_open(const ArchivePlugin *plugin, Path path,
Error &error);
archive_file_open(const ArchivePlugin *plugin, Path path);
#endif

View File

@@ -127,7 +127,7 @@ Bzip2InputStream::Open()
/* archive open && listing routine */
static ArchiveFile *
bz2_open(Path pathname, gcc_unused Error &error)
bz2_open(Path pathname)
{
static Mutex mutex;
static Cond cond;

View File

@@ -123,16 +123,13 @@ Iso9660ArchiveFile::Visit(char *path, size_t length, size_t capacity,
}
static ArchiveFile *
iso9660_archive_open(Path pathname, Error &error)
iso9660_archive_open(Path pathname)
{
/* open archive */
auto iso = iso9660_open(pathname.c_str());
if (iso == nullptr) {
error.Format(iso9660_domain,
"Failed to open ISO9660 file %s",
pathname.c_str());
return nullptr;
}
if (iso == nullptr)
throw FormatRuntimeError("Failed to open ISO9660 file %s",
pathname.c_str());
return new Iso9660ArchiveFile(iso);
}

View File

@@ -68,14 +68,12 @@ static constexpr Domain zzip_domain("zzip");
/* archive open && listing routine */
static ArchiveFile *
zzip_archive_open(Path pathname, Error &error)
zzip_archive_open(Path pathname)
{
ZZIP_DIR *dir = zzip_dir_open(pathname.c_str(), nullptr);
if (dir == nullptr) {
error.Format(zzip_domain, "Failed to open ZIP file %s",
pathname.c_str());
return nullptr;
}
if (dir == nullptr)
throw FormatRuntimeError("Failed to open ZIP file %s",
pathname.c_str());
return new ZzipArchiveFile(dir);
}