command/file: move code to TagScanAny()

This commit is contained in:
Max Kellermann
2019-08-12 19:24:24 +02:00
parent b717ab0383
commit 3895d35a52
4 changed files with 141 additions and 79 deletions

View File

@@ -30,8 +30,7 @@
#include "util/UriExtract.hxx"
#include "tag/Handler.hxx"
#include "tag/Generic.hxx"
#include "TagStream.hxx"
#include "TagFile.hxx"
#include "TagAny.hxx"
#include "storage/StorageInterface.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/FileInfo.hxx"
@@ -150,66 +149,6 @@ public:
}
};
static CommandResult
read_stream_comments(Response &r, const char *uri)
{
PrintCommentHandler h(r);
if (!tag_stream_scan(uri, h)) {
r.Error(ACK_ERROR_NO_EXIST, "Failed to load file");
return CommandResult::ERROR;
}
return CommandResult::OK;
}
static CommandResult
read_file_comments(Response &r, const Path path_fs)
{
PrintCommentHandler h(r);
if (!ScanFileTagsNoGeneric(path_fs, h)) {
r.Error(ACK_ERROR_NO_EXIST, "Failed to load file");
return CommandResult::ERROR;
}
ScanGenericTags(path_fs, h);
return CommandResult::OK;
}
static CommandResult
read_db_comments(Client &client, Response &r, const char *uri)
{
#ifdef ENABLE_DATABASE
const Storage *storage = client.GetStorage();
if (storage == nullptr) {
#else
(void)client;
(void)uri;
#endif
r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
#ifdef ENABLE_DATABASE
}
{
AllocatedPath path_fs = storage->MapFS(uri);
if (!path_fs.IsNull())
return read_file_comments(r, path_fs);
}
{
const std::string uri2 = storage->MapUTF8(uri);
if (uri_has_scheme(uri2.c_str()))
return read_stream_comments(r, uri2.c_str());
}
r.Error(ACK_ERROR_NO_EXIST, "No such file");
return CommandResult::ERROR;
#endif
}
CommandResult
handle_read_comments(Client &client, Request args, Response &r)
{
@@ -217,23 +156,9 @@ handle_read_comments(Client &client, Request args, Response &r)
const char *const uri = args.front();
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri, &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
);
switch (located_uri.type) {
case LocatedUri::Type::ABSOLUTE:
return read_stream_comments(r, located_uri.canonical_uri);
case LocatedUri::Type::RELATIVE:
return read_db_comments(client, r, located_uri.canonical_uri);
case LocatedUri::Type::PATH:
return read_file_comments(r, located_uri.path);
}
gcc_unreachable();
PrintCommentHandler handler(r);
TagScanAny(client, uri, handler);
return CommandResult::OK;
}
/**