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

This commit is contained in:
Max Kellermann
2016-09-09 15:37:06 +02:00
parent 63ab7767a3
commit fc7d3f64c0
44 changed files with 359 additions and 461 deletions

View File

@@ -27,7 +27,7 @@
#endif
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "system/Error.hxx"
#include <assert.h>
@@ -36,20 +36,24 @@
#endif
InputStreamPtr
OpenLocalInputStream(Path path, Mutex &mutex, Cond &cond, Error &error)
OpenLocalInputStream(Path path, Mutex &mutex, Cond &cond)
{
assert(!error.IsDefined());
InputStreamPtr is;
InputStreamPtr is(OpenFileInputStream(path, mutex, cond, error));
#ifdef ENABLE_ARCHIVE
if (is == nullptr && error.IsDomain(errno_domain) &&
error.GetCode() == ENOTDIR) {
/* ENOTDIR means this may be a path inside an archive
file */
Error error2;
is.reset(OpenArchiveInputStream(path, mutex, cond, error2));
if (is == nullptr && error2.IsDefined())
error = std::move(error2);
try {
#endif
is = OpenFileInputStream(path, mutex, cond);
#ifdef ENABLE_ARCHIVE
} catch (const std::system_error &e) {
if (IsPathNotFound(e)) {
/* ENOTDIR means this may be a path inside an archive
file */
is = OpenArchiveInputStream(path, mutex, cond);
if (!is)
throw;
} else
throw;
}
#endif