Code

mpdclient: mpdclient_filelist_get() returns NULL on error
authorMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 17:56:06 +0000 (19:56 +0200)
committerMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 17:56:06 +0000 (19:56 +0200)
Don't artificially return an empty list when an error occurs.
Also don't insert the dummy ".." entry in mpdclient_filelist_get(),
screen_file.c should do this.

src/mpdclient.c
src/screen_file.c

index e331544be34a3e3168ad25fcea6df859fefe8aa6..2d6598518086d5cd080d13aa949207a33a77a7aa 100644 (file)
@@ -689,15 +689,14 @@ mpdclient_filelist_get(struct mpdclient *c, const gchar *path)
 
        mpd_send_list_meta(c->connection, path);
        filelist = filelist_new();
-       if (path && path[0] && strcmp(path, "/"))
-               /* add a dummy entry for ./.. */
-               filelist_append(filelist, NULL);
 
        while ((entity = mpd_recv_entity(c->connection)) != NULL)
                filelist_append(filelist, entity);
 
-       /* If there's an error, ignore it.  We'll return an empty filelist. */
-       mpdclient_finish_command(c);
+       if (mpdclient_finish_command(c)) {
+               filelist_free(filelist);
+               return NULL;
+       }
 
        filelist_sort_dir_play(filelist, compare_filelistentry);
 
index 78052100c9aeede306e7ad290a63b857c1de8970..31af84d8a3f6349571741a636079699d2cc0da73 100644 (file)
@@ -64,6 +64,12 @@ file_reload(struct mpdclient *c)
                filelist_free(browser.filelist);
 
        browser.filelist = mpdclient_filelist_get(c, current_path);
+       if (browser.filelist == NULL)
+               browser.filelist = filelist_new();
+
+       if (*current_path != 0)
+               /* add a dummy entry for ./.. */
+               filelist_prepend(browser.filelist, NULL);
 }
 
 /* the db has changed -> update the filelist */
@@ -289,7 +295,8 @@ static void
 browse_open(G_GNUC_UNUSED struct mpdclient *c)
 {
        if (browser.filelist == NULL) {
-               browser.filelist = mpdclient_filelist_get(c, "");
+               file_reload(c);
+
 #ifndef NCMPC_MINI
                mpdclient_install_playlist_callback(c, playlist_changed_callback);
 #endif