summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-04 01:00:58 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-04 04:32:25 +0200
commit57b4a9688dd2d6f6985906b50aabe8fa0658e14a (patch)
tree8daed9293e5fef9c73228c0d84e4e1ce58938f29
parent653ff1373f08479d712f88d8a478bc5dbda4eaa6 (diff)
downloadnncmpp-57b4a9688dd2d6f6985906b50aabe8fa0658e14a.tar.gz
nncmpp-57b4a9688dd2d6f6985906b50aabe8fa0658e14a.tar.xz
nncmpp-57b4a9688dd2d6f6985906b50aabe8fa0658e14a.zip
Only change path when we get its contents
-rw-r--r--nncmpp.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/nncmpp.c b/nncmpp.c
index d8182d7..9b1bf68 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -1971,9 +1971,16 @@ static void
library_tab_on_data (const struct mpd_response *response,
const struct strv *data, void *user_data)
{
- (void) user_data;
+ char *data_path = user_data;
if (!response->success)
+ {
+ free (data_path);
return;
+ }
+
+ str_reset (&g_library_tab.path);
+ str_append (&g_library_tab.path, data_path);
+ free (data_path);
strv_reset (&g_library_tab.items);
@@ -2017,17 +2024,13 @@ library_tab_on_data (const struct mpd_response *response,
static void
library_tab_reload (const char *new_path)
{
- // TODO: actually we should update the path _after_ we receive data
- struct str *path = &g_library_tab.path;
- if (new_path)
- {
- str_reset (path);
- str_append (path, new_path);
- }
+ char *path = new_path
+ ? xstrdup (new_path)
+ : xstrdup (g_library_tab.path.str);
struct mpd_client *c = &g.client;
- mpd_client_send_command (c, "lsinfo", path->len ? path->str : "/", NULL);
- mpd_client_add_task (c, library_tab_on_data, NULL);
+ mpd_client_send_command (c, "lsinfo", *path ? path : "/", NULL);
+ mpd_client_add_task (c, library_tab_on_data, path);
mpd_client_idle (c, 0);
}