diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/FileCommands.cxx | 37 |
1 files 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; } |