From c488d3123f33fe28525c2b8b229aaae2f9d4dc06 Mon Sep 17 00:00:00 2001 From: FlashSystems Date: Sat, 2 Dec 2017 19:39:17 +0100 Subject: [PATCH] Fix `lsinfo` and `add` for mounted databases. If `SimpleDatabase::Visit` is called on a database that contains a mounted directry the URIs of the elements passed to the callbacks are not prefixed by the mountpoint path. This leads to lsinfo and add not working because they use the wrong URI. This pull request is using the `WalkMount` helper function to create prefixed versions of `VisitDirectory`, `VisitSong` and `VisitPlaylist` to add the correct prefix to the parameters of the callback functions. --- NEWS | 1 + src/db/plugins/simple/Directory.cxx | 2 +- src/db/plugins/simple/Mount.cxx | 4 ++-- src/db/plugins/simple/Mount.hxx | 2 +- src/db/plugins/simple/SimpleDatabasePlugin.cxx | 13 +++++++++++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 5b7c83cfb..c9d376f21 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ ver 0.20.13 (not yet released) * database - simple: don't purge mount points on update/rescan - simple: fix "mount" bug caused by bad compiler optimization + - simple: fix "lsinfo" into mount points - upnp: work around libupnp 1.6.24 API breakage * queue: fix spuriously misplaced prioritized songs * include Windows cross-build script in source tarball diff --git a/src/db/plugins/simple/Directory.cxx b/src/db/plugins/simple/Directory.cxx index 30b044b1f..a1beb344f 100644 --- a/src/db/plugins/simple/Directory.cxx +++ b/src/db/plugins/simple/Directory.cxx @@ -230,7 +230,7 @@ Directory::Walk(bool recursive, const SongFilter *filter, call will lock it again */ const ScopeDatabaseUnlock unlock; WalkMount(GetPath(), *mounted_database, - recursive, filter, + "", recursive, filter, visit_directory, visit_song, visit_playlist); return; diff --git a/src/db/plugins/simple/Mount.cxx b/src/db/plugins/simple/Mount.cxx index bf3a4b815..c07b67abc 100644 --- a/src/db/plugins/simple/Mount.cxx +++ b/src/db/plugins/simple/Mount.cxx @@ -72,7 +72,7 @@ PrefixVisitPlaylist(const char *base, const VisitPlaylist &visit_playlist, void WalkMount(const char *base, const Database &db, - bool recursive, const SongFilter *filter, + const char* uri, bool recursive, const SongFilter *filter, const VisitDirectory &visit_directory, const VisitSong &visit_song, const VisitPlaylist &visit_playlist) { @@ -93,5 +93,5 @@ WalkMount(const char *base, const Database &db, vp = std::bind(PrefixVisitPlaylist, base, std::ref(visit_playlist), _1, _2); - db.Visit(DatabaseSelection("", recursive, filter), vd, vs, vp); + db.Visit(DatabaseSelection(uri, recursive, filter), vd, vs, vp); } diff --git a/src/db/plugins/simple/Mount.hxx b/src/db/plugins/simple/Mount.hxx index 0c6abd1d1..c79e52354 100644 --- a/src/db/plugins/simple/Mount.hxx +++ b/src/db/plugins/simple/Mount.hxx @@ -27,7 +27,7 @@ class SongFilter; void WalkMount(const char *base, const Database &db, - bool recursive, const SongFilter *filter, + const char* uri, bool recursive, const SongFilter *filter, const VisitDirectory &visit_directory, const VisitSong &visit_song, const VisitPlaylist &visit_playlist); diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 9f06105f5..a27c070c6 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "SimpleDatabasePlugin.hxx" #include "PrefixedLightSong.hxx" +#include "Mount.hxx" #include "db/DatabasePlugin.hxx" #include "db/Selection.hxx" #include "db/Helpers.hxx" @@ -270,6 +271,18 @@ SimpleDatabase::Visit(const DatabaseSelection &selection, ScopeDatabaseLock protect; auto r = root->LookupDirectory(selection.uri.c_str()); + + if (r.directory->IsMount()) { + /* pass the request and the remaining uri to the mounted database */ + protect.unlock(); + + WalkMount(r.directory->GetPath(), *(r.directory->mounted_database), + (r.uri == nullptr)?"":r.uri, selection.recursive, selection.filter, + visit_directory, visit_song, visit_playlist); + + return; + } + if (r.uri == nullptr) { /* it's a directory */