Commit 676dfabc authored by Max Kellermann's avatar Max Kellermann

command/{Queue,File}Commands: drop "file:///" prefix for absolute paths

Requiring this prefix makes the client's intention very clear, but it was too hard to understand why this prefix was needed. Initially, my intention was to differentiate from broken clients which prefix relate URIs with a slash; once MPD allowed that. In the past few years however, MPD has disallowed that, and there was no significant breakage (except for the "add /" special case which some clients apparently still do). So I figure it's about time to define that an URI that begins with a slash points to an arbitrary file on the file system.
parent 60e6d1d6
...@@ -4,6 +4,7 @@ ver 0.20 (not yet released) ...@@ -4,6 +4,7 @@ ver 0.20 (not yet released)
- "search"/"find" have a "window" parameter - "search"/"find" have a "window" parameter
- report song duration with milliseconds precision - report song duration with milliseconds precision
- "sticker find" can match sticker values - "sticker find" can match sticker values
- drop the "file:///" prefix for absolute file paths
* tags * tags
- ape, ogg: drop support for non-standard tag "album artist" - ape, ogg: drop support for non-standard tag "album artist"
affected filetypes: vorbis, flac, opus & all files with ape2 tags affected filetypes: vorbis, flac, opus & all files with ape2 tags
......
...@@ -1772,7 +1772,7 @@ OK ...@@ -1772,7 +1772,7 @@ OK
<para> <para>
Clients that are connected via UNIX domain socket may Clients that are connected via UNIX domain socket may
use this command to read the tags of an arbitrary local use this command to read the tags of an arbitrary local
file (URI beginning with "file:///"). file (URI is an absolute path).
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1787,8 +1787,7 @@ OK ...@@ -1787,8 +1787,7 @@ OK
<para> <para>
Read "comments" (i.e. key-value pairs) from the file Read "comments" (i.e. key-value pairs) from the file
specified by "URI". This "URI" can be a path relative specified by "URI". This "URI" can be a path relative
to the music directory or a URL in the form to the music directory or an absolute path.
"file:///foo/bar.ogg".
</para> </para>
<para> <para>
This command may be used to list metadata of remote This command may be used to list metadata of remote
......
...@@ -202,11 +202,22 @@ read_file_comments(Client &client, const Path path_fs) ...@@ -202,11 +202,22 @@ read_file_comments(Client &client, const Path path_fs)
} }
static const char *
translate_uri(const char *uri)
{
if (memcmp(uri, "file:///", 8) == 0)
/* drop the "file://", leave only an absolute path
(starting with a slash) */
return uri + 7;
return uri;
}
CommandResult CommandResult
handle_read_comments(Client &client, ConstBuffer<const char *> args) handle_read_comments(Client &client, ConstBuffer<const char *> args)
{ {
assert(args.size == 1); assert(args.size == 1);
const char *const uri = args.front(); const char *const uri = translate_uri(args.front());
if (memcmp(uri, "file:///", 8) == 0) { if (memcmp(uri, "file:///", 8) == 0) {
/* read comments from arbitrary local file */ /* read comments from arbitrary local file */
......
...@@ -43,18 +43,13 @@ ...@@ -43,18 +43,13 @@
#include <string.h> #include <string.h>
static const char * static const char *
translate_uri(Client &client, const char *uri) translate_uri(const char *uri)
{ {
if (memcmp(uri, "file:///", 8) == 0) if (memcmp(uri, "file:///", 8) == 0)
/* drop the "file://", leave only an absolute path /* drop the "file://", leave only an absolute path
(starting with a slash) */ (starting with a slash) */
return uri + 7; return uri + 7;
if (PathTraitsUTF8::IsAbsolute(uri)) {
command_error(client, ACK_ERROR_NO_EXIST, "Malformed URI");
return nullptr;
}
return uri; return uri;
} }
...@@ -70,9 +65,7 @@ handle_add(Client &client, ConstBuffer<const char *> args) ...@@ -70,9 +65,7 @@ handle_add(Client &client, ConstBuffer<const char *> args)
here */ here */
uri = ""; uri = "";
uri = translate_uri(client, uri); uri = translate_uri(uri);
if (uri == nullptr)
return CommandResult::ERROR;
if (uri_has_scheme(uri) || PathTraitsUTF8::IsAbsolute(uri)) { if (uri_has_scheme(uri) || PathTraitsUTF8::IsAbsolute(uri)) {
const SongLoader loader(client); const SongLoader loader(client);
...@@ -101,9 +94,7 @@ handle_add(Client &client, ConstBuffer<const char *> args) ...@@ -101,9 +94,7 @@ handle_add(Client &client, ConstBuffer<const char *> args)
CommandResult CommandResult
handle_addid(Client &client, ConstBuffer<const char *> args) handle_addid(Client &client, ConstBuffer<const char *> args)
{ {
const char *const uri = translate_uri(client, args.front()); const char *const uri = translate_uri(args.front());
if (uri == nullptr)
return CommandResult::ERROR;
const SongLoader loader(client); const SongLoader loader(client);
Error error; Error error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment