From a688745bdc6db32e2cb7765c5d113958dcd49411 Mon Sep 17 00:00:00 2001 From: Denis Krjuchkov Date: Sun, 5 May 2013 15:42:29 +0600 Subject: ClientFile: use Path and file system API, update usages accordingly This commit also fixes incorrect passing of UTF-8 strings to client_allow_file --- src/ClientFile.cxx | 6 ++++-- src/ClientFile.hxx | 3 ++- src/OtherCommands.cxx | 10 +++++++++- src/QueueCommands.cxx | 27 +++++++++++++++++++++------ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/ClientFile.cxx b/src/ClientFile.cxx index dccf0a327..07fa767b0 100644 --- a/src/ClientFile.cxx +++ b/src/ClientFile.cxx @@ -22,6 +22,8 @@ #include "Client.hxx" #include "ack.h" #include "io_error.h" +#include "fs/Path.hxx" +#include "fs/FileSystem.hxx" #include #include @@ -29,7 +31,7 @@ #include bool -client_allow_file(const Client *client, const char *path_fs, +client_allow_file(const Client *client, const Path &path_fs, GError **error_r) { #ifdef WIN32 @@ -54,7 +56,7 @@ client_allow_file(const Client *client, const char *path_fs, } struct stat st; - if (stat(path_fs, &st) < 0) { + if (!StatFile(path_fs, st)) { set_error_errno(error_r); return false; } diff --git a/src/ClientFile.hxx b/src/ClientFile.hxx index 48e00c44f..c2ea25f51 100644 --- a/src/ClientFile.hxx +++ b/src/ClientFile.hxx @@ -25,6 +25,7 @@ #include class Client; +class Path; /** * Is this client allowed to use the specified local file? @@ -37,7 +38,7 @@ class Client; * @return true if access is allowed */ bool -client_allow_file(const Client *client, const char *path_fs, +client_allow_file(const Client *client, const Path &path_fs, GError **error_r); #endif diff --git a/src/OtherCommands.cxx b/src/OtherCommands.cxx index 07fbc8442..7f592ee9f 100644 --- a/src/OtherCommands.cxx +++ b/src/OtherCommands.cxx @@ -34,6 +34,7 @@ #include "ls.hxx" #include "Volume.hxx" #include "util/UriUtil.hxx" +#include "fs/Path.hxx" extern "C" { #include "stats.h" @@ -117,9 +118,16 @@ handle_lsinfo(Client *client, int argc, char *argv[]) if (strncmp(uri, "file:///", 8) == 0) { /* print information about an arbitrary local file */ const char *path_utf8 = uri + 7; + const Path path_fs = Path::FromUTF8(path_utf8); + + if (path_fs.IsNull()) { + command_error(client, ACK_ERROR_NO_EXIST, + "unsupported file name"); + return COMMAND_RETURN_ERROR; + } GError *error = NULL; - if (!client_allow_file(client, path_utf8, &error)) + if (!client_allow_file(client, path_fs, &error)) return print_error(client, error); struct song *song = song_file_load(path_utf8, NULL); diff --git a/src/QueueCommands.cxx b/src/QueueCommands.cxx index aac6d5a51..210b1501a 100644 --- a/src/QueueCommands.cxx +++ b/src/QueueCommands.cxx @@ -32,6 +32,7 @@ #include "protocol/Result.hxx" #include "ls.hxx" #include "util/UriUtil.hxx" +#include "fs/Path.hxx" #include @@ -42,13 +43,20 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[]) enum playlist_result result; if (strncmp(uri, "file:///", 8) == 0) { - const char *path = uri + 7; + const char *path_utf8 = uri + 7; + const Path path_fs = Path::FromUTF8(path_utf8); + + if (path_fs.IsNull()) { + command_error(client, ACK_ERROR_NO_EXIST, + "unsupported file name"); + return COMMAND_RETURN_ERROR; + } GError *error = NULL; - if (!client_allow_file(client, path, &error)) + if (!client_allow_file(client, path_fs, &error)) return print_error(client, error); - result = client->partition.AppendFile(path); + result = client->partition.AppendFile(path_utf8); return print_playlist_result(client, result); } @@ -78,13 +86,20 @@ handle_addid(Client *client, int argc, char *argv[]) enum playlist_result result; if (strncmp(uri, "file:///", 8) == 0) { - const char *path = uri + 7; + const char *path_utf8 = uri + 7; + const Path path_fs = Path::FromUTF8(path_utf8); + + if (path_fs.IsNull()) { + command_error(client, ACK_ERROR_NO_EXIST, + "unsupported file name"); + return COMMAND_RETURN_ERROR; + } GError *error = NULL; - if (!client_allow_file(client, path, &error)) + if (!client_allow_file(client, path_fs, &error)) return print_error(client, error); - result = client->partition.AppendFile(path, &added_id); + result = client->partition.AppendFile(path_utf8, &added_id); } else { if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) { command_error(client, ACK_ERROR_NO_EXIST, -- cgit v1.2.3