ArchivePlugin: pass Path to open()

This commit is contained in:
Max Kellermann 2014-02-08 13:21:50 +01:00
parent 9906daeca7
commit fe7c6fee34
8 changed files with 25 additions and 17 deletions

View File

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

View File

@ -21,6 +21,7 @@
#define MPD_ARCHIVE_PLUGIN_HXX #define MPD_ARCHIVE_PLUGIN_HXX
class ArchiveFile; class ArchiveFile;
class Path;
class Error; class Error;
struct ArchivePlugin { struct ArchivePlugin {
@ -44,7 +45,7 @@ struct ArchivePlugin {
* returns pointer to handle used is all operations with this archive * returns pointer to handle used is all operations with this archive
* or nullptr when opening fails * or nullptr when opening fails
*/ */
ArchiveFile *(*open)(const char *path_fs, Error &error); ArchiveFile *(*open)(Path path_fs, Error &error);
/** /**
* suffixes handled by this plugin. * suffixes handled by this plugin.
@ -54,7 +55,7 @@ struct ArchivePlugin {
}; };
ArchiveFile * ArchiveFile *
archive_file_open(const ArchivePlugin *plugin, const char *path, archive_file_open(const ArchivePlugin *plugin, Path path,
Error &error); Error &error);
#endif #endif

View File

@ -32,6 +32,7 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "fs/Path.hxx"
#include <bzlib.h> #include <bzlib.h>
@ -49,9 +50,9 @@ public:
std::string name; std::string name;
InputStream *const istream; InputStream *const istream;
Bzip2ArchiveFile(const char *path, InputStream *_is) Bzip2ArchiveFile(Path path, InputStream *_is)
:ArchiveFile(bz2_archive_plugin), :ArchiveFile(bz2_archive_plugin),
name(PathTraitsUTF8::GetBase(path)), name(PathTraitsFS::GetBase(path.c_str())),
istream(_is) { istream(_is) {
// remove .bz2 suffix // remove .bz2 suffix
const size_t len = name.length(); const size_t len = name.length();
@ -142,11 +143,12 @@ Bzip2InputStream::Close()
/* archive open && listing routine */ /* archive open && listing routine */
static ArchiveFile * static ArchiveFile *
bz2_open(const char *pathname, Error &error) bz2_open(Path pathname, Error &error)
{ {
static Mutex mutex; static Mutex mutex;
static Cond cond; static Cond cond;
InputStream *is = InputStream::OpenReady(pathname, mutex, cond, error); InputStream *is = InputStream::OpenReady(pathname.c_str(), mutex, cond,
error);
if (is == nullptr) if (is == nullptr)
return nullptr; return nullptr;

View File

@ -28,6 +28,7 @@
#include "../ArchiveVisitor.hxx" #include "../ArchiveVisitor.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/InputPlugin.hxx" #include "input/InputPlugin.hxx"
#include "fs/Path.hxx"
#include "util/RefCount.hxx" #include "util/RefCount.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
@ -117,13 +118,14 @@ Iso9660ArchiveFile::Visit(const char *psz_path, ArchiveVisitor &visitor)
} }
static ArchiveFile * static ArchiveFile *
iso9660_archive_open(const char *pathname, Error &error) iso9660_archive_open(Path pathname, Error &error)
{ {
/* open archive */ /* open archive */
auto iso = iso9660_open(pathname); auto iso = iso9660_open(pathname.c_str());
if (iso == nullptr) { if (iso == nullptr) {
error.Format(iso9660_domain, error.Format(iso9660_domain,
"Failed to open ISO9660 file %s", pathname); "Failed to open ISO9660 file %s",
pathname.c_str());
return nullptr; return nullptr;
} }

View File

@ -28,6 +28,7 @@
#include "../ArchiveVisitor.hxx" #include "../ArchiveVisitor.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "input/InputPlugin.hxx" #include "input/InputPlugin.hxx"
#include "fs/Path.hxx"
#include "util/RefCount.hxx" #include "util/RefCount.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
@ -70,12 +71,12 @@ static constexpr Domain zzip_domain("zzip");
/* archive open && listing routine */ /* archive open && listing routine */
static ArchiveFile * static ArchiveFile *
zzip_archive_open(const char *pathname, Error &error) zzip_archive_open(Path pathname, Error &error)
{ {
ZZIP_DIR *dir = zzip_dir_open(pathname, nullptr); ZZIP_DIR *dir = zzip_dir_open(pathname.c_str(), nullptr);
if (dir == nullptr) { if (dir == nullptr) {
error.Format(zzip_domain, "Failed to open ZIP file %s", error.Format(zzip_domain, "Failed to open ZIP file %s",
pathname); pathname.c_str());
return nullptr; return nullptr;
} }

View File

@ -125,7 +125,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
/* open archive */ /* open archive */
Error error; Error error;
ArchiveFile *file = archive_file_open(&plugin, path_fs.c_str(), error); ArchiveFile *file = archive_file_open(&plugin, path_fs, error);
if (file == nullptr) { if (file == nullptr) {
LogError(error); LogError(error);
if (directory != nullptr) if (directory != nullptr)

View File

@ -26,6 +26,7 @@
#include "archive/ArchiveFile.hxx" #include "archive/ArchiveFile.hxx"
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "fs/Path.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -69,7 +70,7 @@ input_archive_open(const char *pathname,
return nullptr; return nullptr;
} }
auto file = archive_file_open(arplug, archive, error); auto file = archive_file_open(arplug, Path::FromFS(archive), error);
if (file == nullptr) { if (file == nullptr) {
free(pname); free(pname);
return nullptr; return nullptr;

View File

@ -85,7 +85,7 @@ main(int argc, char **argv)
int result = EXIT_SUCCESS; int result = EXIT_SUCCESS;
ArchiveFile *file = archive_file_open(plugin, path.c_str(), error); ArchiveFile *file = archive_file_open(plugin, path, error);
if (file != nullptr) { if (file != nullptr) {
MyArchiveVisitor visitor; MyArchiveVisitor visitor;
file->Visit(visitor); file->Visit(visitor);