Hi.
I have made a little patch on mpd to allow you to give the absolute path of a file to be added. It is a modification to the traverseAllIn function. So it will also affect searches, counts, sums of song times. If the path to be added/searched does not return a true file in the database and starts with the music_dir configuration variable, the traverseAllIn is called once more without the leading music_dir value.
Index: src/directory.c
===================================================================
--- src/directory.c (revision 3266)
+++ src/directory.c (working copy)
@@ -1174,12 +1174,24 @@
int (*forEachDir)(FILE *, Directory *, void *),
void * data) {
Directory * directory;
+ const char* musicdir;
+ size_t musicdir_len;
if((directory = getDirectory(name))==NULL) {
Song * song;
if((song = getSongFromDB(name)) && forEachSong) {
return forEachSong(fp, song, data);
}
+ else if(name && (musicdir = getConfigParamValue(CONF_MUSIC_DIR))
+ && (musicdir_len = strlen(musicdir))
+ && musicdir_len<strlen(name)
+ && strncmp(musicdir, name, musicdir_len)==0
+ && (song = getSongFromDB(name+musicdir_len)))
+ {
+ return traverseAllIn(fp, name+musicdir_len,
+ forEachSong, forEachDir, data);
+ }
+
commandError(fp, ACK_ERROR_NO_EXIST,
"directory or file not found", NULL);
return -1;
The reason I wanted it, was that I wanted to implement a drag-and-drop function in the client I have been playing with. I ended up just trying to strip one element of the path off at a time until it worked. I didn't think this was a clean solution:
QStringList path=QStringList::split("/",(*i).path());
while (!path.empty())
{
if (dispatch((QString("add \"")
+path.join("/").replace("\"","\\\"")
+QString("\"\n")).latin1()))
{
if (fetchOk()) break;
}
path.pop_front();
}
The alternative tactic might have been to somehow expose the server's music_dir configuration directive to the client, but this would have required more code and more work on the client side.
I would also have liked to patch mpc so that i could add absolute paths (and use my shell's tab completion from any directory, not just when i'm cd'd into music_dir). However, mpc actually checks to see if the file exists in the database before it even tries to add it.
I'm interested if anyone else has an opinion on this.
