From 9fff02841b8c20d52e6d6a95276ed461cea525d5 Mon Sep 17 00:00:00 2001 From: chme Date: Mon, 28 Jan 2019 14:46:36 +0100 Subject: [PATCH] [jsonapi] Fix error in web interface files-view if the library directory end with a trailing slash --- src/httpd_jsonapi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index c7a1042c..a97be341 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -30,10 +30,12 @@ # include #endif +#include #include #include #include #include +#include #include #include @@ -636,6 +638,7 @@ jsonapi_reply_config(struct httpd_request *hreq) cfg_t *lib; int ndirs; char *path; + char *deref; json_object *directories; int i; @@ -674,7 +677,18 @@ jsonapi_reply_config(struct httpd_request *hreq) for (i = 0; i < ndirs; i++) { path = cfg_getnstr(lib, "directories", i); - json_object_array_add(directories, json_object_new_string(path)); + + // The path in the conf file may have a trailing slash character. Return the realpath like it is done in the bulk_scan function in filescanner.c + deref = realpath(path, NULL); + if (deref) + { + json_object_array_add(directories, json_object_new_string(deref)); + free(deref); + } + else + { + DPRINTF(E_LOG, L_WEB, "Skipping library directory %s, could not dereference: %s\n", path, strerror(errno)); + } } json_object_object_add(jreply, "directories", directories);