From 8fd8f23a6be0266c80d62f80b21b35b1fb49ae76 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 7 Feb 2014 18:33:43 +0100 Subject: FileCommands: move code to read_file_comments() --- src/command/FileCommands.cxx | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index cfd5e3926..709cc3dc0 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -101,6 +101,22 @@ read_stream_comments(Client &client, const char *uri) } +static CommandResult +read_file_comments(Client &client, const Path path_fs) +{ + if (!tag_file_scan(path_fs, print_comment_handler, &client)) { + command_error(client, ACK_ERROR_NO_EXIST, + "Failed to load file"); + return CommandResult::ERROR; + } + + tag_ape_scan2(path_fs, &print_comment_handler, &client); + tag_id3_scan(path_fs, &print_comment_handler, &client); + + return CommandResult::OK; + +} + CommandResult handle_read_comments(Client &client, gcc_unused int argc, char *argv[]) { @@ -108,12 +124,10 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[]) const char *const uri = argv[1]; - AllocatedPath path_fs = AllocatedPath::Null(); - if (memcmp(uri, "file:///", 8) == 0) { /* read comments from arbitrary local file */ const char *path_utf8 = uri + 7; - path_fs = AllocatedPath::FromUTF8(path_utf8); + AllocatedPath path_fs = AllocatedPath::FromUTF8(path_utf8); if (path_fs.IsNull()) { command_error(client, ACK_ERROR_NO_EXIST, "unsupported file name"); @@ -123,16 +137,20 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[]) Error error; if (!client.AllowFile(path_fs, error)) return print_error(client, error); + + return read_file_comments(client, path_fs); } else if (uri_has_scheme(uri)) { return read_stream_comments(client, uri); } else if (!PathTraitsUTF8::IsAbsolute(uri)) { #ifdef ENABLE_DATABASE - path_fs = map_uri_fs(uri); + AllocatedPath path_fs = map_uri_fs(uri); if (path_fs.IsNull()) { command_error(client, ACK_ERROR_NO_EXIST, "No such file"); return CommandResult::ERROR; } + + return read_file_comments(client, path_fs); #else command_error(client, ACK_ERROR_NO_EXIST, "No database"); return CommandResult::ERROR; @@ -141,15 +159,4 @@ handle_read_comments(Client &client, gcc_unused int argc, char *argv[]) command_error(client, ACK_ERROR_NO_EXIST, "No such file"); return CommandResult::ERROR; } - - if (!tag_file_scan(path_fs, print_comment_handler, &client)) { - command_error(client, ACK_ERROR_NO_EXIST, - "Failed to load file"); - return CommandResult::ERROR; - } - - tag_ape_scan2(path_fs, &print_comment_handler, &client); - tag_id3_scan(path_fs, &print_comment_handler, &client); - - return CommandResult::OK; } -- cgit v1.2.3