aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-07-25 13:18:57 +0200
committerMax Kellermann <max@duempel.org>2010-07-25 13:28:39 +0200
commitb233c145fa28f2a9e90a40993bc35f408d256e08 (patch)
tree81a4520fde88423f5654c3c97fc748ca7065f44e
parent9de5bb9e23915f847b59d32d9e857c45974b01d7 (diff)
downloadmpd-b233c145fa28f2a9e90a40993bc35f408d256e08.tar.gz
mpd-b233c145fa28f2a9e90a40993bc35f408d256e08.tar.xz
mpd-b233c145fa28f2a9e90a40993bc35f408d256e08.zip
{queue,song}_print: print relative paths if possible
If a song with an absolute path points inside the music directory, print only the relative part. This happens when partial songs from a playlist file were loaded.
Diffstat (limited to '')
-rw-r--r--src/mapper.c10
-rw-r--r--src/mapper.h8
-rw-r--r--src/queue_print.c1
-rw-r--r--src/song_print.c4
4 files changed, 22 insertions, 1 deletions
diff --git a/src/mapper.c b/src/mapper.c
index 03822ca9e..108de9531 100644
--- a/src/mapper.c
+++ b/src/mapper.c
@@ -93,6 +93,16 @@ mapper_has_music_directory(void)
return music_dir != NULL;
}
+const char *
+map_to_relative_path(const char *path_utf8)
+{
+ return music_dir != NULL &&
+ memcmp(path_utf8, music_dir, music_dir_length) == 0 &&
+ G_IS_DIR_SEPARATOR(path_utf8[music_dir_length])
+ ? path_utf8 + music_dir_length + 1
+ : path_utf8;
+}
+
char *
map_uri_fs(const char *uri)
{
diff --git a/src/mapper.h b/src/mapper.h
index 3575a0e9d..9f84f96fe 100644
--- a/src/mapper.h
+++ b/src/mapper.h
@@ -42,6 +42,14 @@ bool
mapper_has_music_directory(void);
/**
+ * If the specified absolute path points inside the music directory,
+ * this function converts it to a relative path. If not, it returns
+ * the unmodified string pointer.
+ */
+const char *
+map_to_relative_path(const char *path_utf8);
+
+/**
* Determines the absolute file system path of a relative URI. This
* is basically done by converting the URI to the file system charset
* and prepending the music directory.
diff --git a/src/queue_print.c b/src/queue_print.c
index 3b49dee61..53ddfb689 100644
--- a/src/queue_print.c
+++ b/src/queue_print.c
@@ -24,6 +24,7 @@
#include "song_print.h"
#include "locate.h"
#include "client.h"
+#include "mapper.h"
/**
* Send detailed information about a range of songs in the queue to a
diff --git a/src/song_print.c b/src/song_print.c
index 11b241fbc..16239e03b 100644
--- a/src/song_print.c
+++ b/src/song_print.c
@@ -25,6 +25,7 @@
#include "tag_print.h"
#include "client.h"
#include "uri.h"
+#include "mapper.h"
void
song_print_uri(struct client *client, struct song *song)
@@ -40,7 +41,8 @@ song_print_uri(struct client *client, struct song *song)
if (uri == NULL)
uri = song->uri;
- client_printf(client, "%s%s\n", SONG_FILE, uri);
+ client_printf(client, "%s%s\n", SONG_FILE,
+ map_to_relative_path(uri));
g_free(allocated);
}