From 92f09bba949c5a32b3e43293e08682b038b0b065 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 18 Jan 2018 22:05:04 +0100
Subject: [PATCH 01/16] Makefile.am: rename JAVA_SOURCES to JAVA_SOURCE_PATHS

Work around automake warning:

    Makefile.am:310: warning: variable 'JAVA_SOURCES' is defined but no program or
    Makefile.am:310: library has 'JAVA' as canonical name (possible typo)

Closes #195
---
 Makefile.am | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index c0ccec411..39bd18011 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -307,7 +307,7 @@ ANDROID_XML_RES := $(wildcard $(srcdir)/android/res/*/*.xml)
 ANDROID_XML_RES_COPIES := $(patsubst $(srcdir)/android/%,android/build/%,$(ANDROID_XML_RES))
 
 JAVA_SOURCE_NAMES = Bridge.java Loader.java Main.java
-JAVA_SOURCES = $(addprefix $(srcdir)/android/src/,$(JAVA_SOURCE_NAMES))
+JAVA_SOURCE_PATHS = $(addprefix $(srcdir)/android/src/,$(JAVA_SOURCE_NAMES))
 
 JAVA_CLASSFILES_DIR = android/build/classes
 
@@ -328,7 +328,7 @@ android/build/resources.apk: $(ANDROID_XML_RES_COPIES) android/build/res/drawabl
 # R.java is generated by aapt, when resources.apk is generated
 android/build/gen/org/musicpd/R.java: android/build/resources.apk
 
-android/build/classes.dex: $(JAVA_SOURCES) android/build/gen/org/musicpd/R.java
+android/build/classes.dex: $(JAVA_SOURCE_PATHS) android/build/gen/org/musicpd/R.java
 	@$(MKDIR_P) $(JAVA_CLASSFILES_DIR)
 	$(JAVAC) -source 1.5 -target 1.5 -Xlint:-options \
 		-cp $(ANDROID_SDK_PLATFORM_DIR)/android.jar:$(JAVA_CLASSFILES_DIR) \

From 272167b4fcc0c76dc3870b33c4246a00ab724968 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 18 Jan 2018 22:07:28 +0100
Subject: [PATCH 02/16] python/build/libs.py: update LAME to 3.100

---
 python/build/libs.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/build/libs.py b/python/build/libs.py
index 0ad195798..a4de2e2a3 100644
--- a/python/build/libs.py
+++ b/python/build/libs.py
@@ -83,8 +83,8 @@ libmad = AutotoolsProject(
 )
 
 liblame = AutotoolsProject(
-    'http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz',
-    '24346b4158e4af3bd9f2e194bb23eb473c75fb7377011523353196b19b9a23ff',
+    'http://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz',
+    'ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e',
     'lib/libmp3lame.a',
     [
         '--disable-shared', '--enable-static',

From 823134e4ba741312086010d6859c852f2be126e2 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 11:32:34 +0100
Subject: [PATCH 03/16] python/build/libs.py: disable Opus documentation and
 extra programs

---
 python/build/libs.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/python/build/libs.py b/python/build/libs.py
index a4de2e2a3..ad6d15fe3 100644
--- a/python/build/libs.py
+++ b/python/build/libs.py
@@ -29,6 +29,8 @@ opus = AutotoolsProject(
     'lib/libopus.a',
     [
         '--disable-shared', '--enable-static',
+        '--disable-doc',
+        '--disable-extra-programs',
     ],
 
     # suppress "visibility default" from opus_defines.h

From a53d081c39b592f71859d4b22536a8a8c60906e8 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 11:38:18 +0100
Subject: [PATCH 04/16] python/build/libs.py: disable libFLAC API documentation

---
 python/build/libs.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/python/build/libs.py b/python/build/libs.py
index ad6d15fe3..b4cb2a55a 100644
--- a/python/build/libs.py
+++ b/python/build/libs.py
@@ -44,6 +44,7 @@ flac = AutotoolsProject(
     [
         '--disable-shared', '--enable-static',
         '--disable-xmms-plugin', '--disable-cpplibs',
+        '--disable-doxygen-docs',
     ],
 )
 

From 34b8a17ccd41343e899388d85ae22431456a196f Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 11:39:33 +0100
Subject: [PATCH 05/16] python/build/autotools.py: add "subdir" parameter

---
 python/build/autotools.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/python/build/autotools.py b/python/build/autotools.py
index 56af64cce..58d5d8c54 100644
--- a/python/build/autotools.py
+++ b/python/build/autotools.py
@@ -8,6 +8,7 @@ class AutotoolsProject(MakeProject):
                  cppflags='',
                  ldflags='',
                  libs='',
+                 subdirs=None,
                  **kwargs):
         MakeProject.__init__(self, url, md5, installed, **kwargs)
         self.configure_args = configure_args
@@ -15,6 +16,7 @@ class AutotoolsProject(MakeProject):
         self.cppflags = cppflags
         self.ldflags = ldflags
         self.libs = libs
+        self.subdirs = subdirs
 
     def configure(self, toolchain):
         src = self.unpack(toolchain)
@@ -51,4 +53,8 @@ class AutotoolsProject(MakeProject):
 
     def build(self, toolchain):
         build = self.configure(toolchain)
-        MakeProject.build(self, toolchain, build)
+        if self.subdirs is not None:
+            for subdir in self.subdirs:
+                MakeProject.build(self, toolchain, os.path.join(build, subdir))
+        else:
+            MakeProject.build(self, toolchain, build)

From ead9d59e8805890c129e545f1b20776eb1a48838 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 11:40:47 +0100
Subject: [PATCH 06/16] python/build/libs.py: build only libFLAC, no programs

---
 python/build/libs.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/python/build/libs.py b/python/build/libs.py
index b4cb2a55a..a70cf5d1f 100644
--- a/python/build/libs.py
+++ b/python/build/libs.py
@@ -46,6 +46,7 @@ flac = AutotoolsProject(
         '--disable-xmms-plugin', '--disable-cpplibs',
         '--disable-doxygen-docs',
     ],
+    subdirs=['include', 'src/libFLAC'],
 )
 
 zlib = ZlibProject(

From fcaedec2ab027971fdb342d257c4af6d3560edde Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 11:18:45 +0100
Subject: [PATCH 07/16] {android,win32}/build.py: move "-O* -g" to common_flags

---
 android/build.py | 7 ++++---
 win32/build.py   | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/android/build.py b/android/build.py
index edabccf01..393f1d7da 100755
--- a/android/build.py
+++ b/android/build.py
@@ -65,7 +65,8 @@ class AndroidNdkToolchain:
         llvm_path = os.path.join(ndk_path, 'toolchains', 'llvm', 'prebuilt', build_arch)
         llvm_triple = 'armv7-none-linux-androideabi'
 
-        common_flags = '-march=armv7-a -mfloat-abi=softfp'
+        common_flags = '-Os -g'
+        common_flags += ' -march=armv7-a -mfloat-abi=softfp'
 
         toolchain_bin = os.path.join(toolchain_path, 'bin')
         llvm_bin = os.path.join(llvm_path, 'bin')
@@ -80,8 +81,8 @@ class AndroidNdkToolchain:
         self.nm = os.path.join(toolchain_bin, arch + '-nm')
         self.strip = os.path.join(toolchain_bin, arch + '-strip')
 
-        self.cflags = '-Os -g ' + common_flags
-        self.cxxflags = '-Os -g ' + common_flags
+        self.cflags = common_flags
+        self.cxxflags = common_flags
         self.cppflags = '--sysroot=' + sysroot + \
             ' -isystem ' + os.path.join(install_prefix, 'include') + \
             ' -isystem ' + os.path.join(sysroot, 'usr', 'include', arch) + \
diff --git a/win32/build.py b/win32/build.py
index d2b1aef1a..45c5dfa4c 100755
--- a/win32/build.py
+++ b/win32/build.py
@@ -50,14 +50,14 @@ class CrossGccToolchain:
         self.nm = os.path.join(toolchain_bin, arch + '-nm')
         self.strip = os.path.join(toolchain_bin, arch + '-strip')
 
-        common_flags = ''
+        common_flags = '-O2 -g'
 
         if not x64:
             # enable SSE support which is required for LAME
             common_flags += ' -march=pentium3'
 
-        self.cflags = '-O2 -g ' + common_flags
-        self.cxxflags = '-O2 -g ' + common_flags
+        self.cflags = common_flags
+        self.cxxflags = common_flags
         self.cppflags = '-isystem ' + os.path.join(install_prefix, 'include')
         self.ldflags = '-L' + os.path.join(install_prefix, 'lib')
         self.libs = ''

From cad5d11261de8fea87b8568587f698cb0794e77f Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 22:36:03 +0100
Subject: [PATCH 08/16] android/build.py: simplify libc++ flags

By telling clang which implementation to use, we avoid the dependency
on libstdc++.so.
---
 android/build.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/android/build.py b/android/build.py
index 393f1d7da..c2ee971e2 100755
--- a/android/build.py
+++ b/android/build.py
@@ -101,15 +101,13 @@ class AndroidNdkToolchain:
         libcxx_path = os.path.join(ndk_path, 'sources/cxx-stl/llvm-libc++')
         libcxx_libs_path = os.path.join(libcxx_path, 'libs', android_abi)
 
-        libstdcxx_cppflags = '-nostdinc++ -isystem ' + os.path.join(libcxx_path, 'include') + ' -isystem ' + os.path.join(ndk_path, 'sources/android/support/include')
-        libstdcxx_ldadd = os.path.join(libcxx_libs_path, 'libc++_static.a') + ' ' + os.path.join(libcxx_libs_path, 'libc++abi.a')
-
-        if self.is_armv7:
-            libstdcxx_ldadd += ' ' + os.path.join(libcxx_libs_path, 'libunwind.a')
+        libstdcxx_flags = '-stdlib=libc++'
+        libstdcxx_cxxflags = libstdcxx_flags + ' -isystem ' + os.path.join(libcxx_path, 'include') + ' -isystem ' + os.path.join(ndk_path, 'sources/android/support/include')
+        libstdcxx_ldflags = libstdcxx_flags + ' -static-libstdc++ -L' + libcxx_libs_path
 
         if use_cxx:
-            self.libs += ' ' + libstdcxx_ldadd
-            self.cppflags += ' ' + libstdcxx_cppflags
+            self.cxxflags += ' ' + libstdcxx_cxxflags
+            self.ldflags += ' ' + libstdcxx_ldflags
 
         self.env = dict(os.environ)
 

From 9e058732ee2d7bf82f2795c4f964197bc619dc77 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 12:55:57 +0100
Subject: [PATCH 09/16] android/build.py: add -fpic

Android native code should be position-independent.

The NDK build scripts use "-fpic" instead of "-fPIC" for ARM, but that
doesn't work with FFmpeg's assembly code, because it requires
R_ARM_MOVW_ABS_NC which is unavailable with "-fpic".
---
 android/build.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/android/build.py b/android/build.py
index c2ee971e2..0b001e7da 100755
--- a/android/build.py
+++ b/android/build.py
@@ -66,6 +66,7 @@ class AndroidNdkToolchain:
         llvm_triple = 'armv7-none-linux-androideabi'
 
         common_flags = '-Os -g'
+        common_flags += ' -fPIC'
         common_flags += ' -march=armv7-a -mfloat-abi=softfp'
 
         toolchain_bin = os.path.join(toolchain_path, 'bin')

From d029dae7adcb771e4d4f59b9f42d1f01337d690d Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:04:54 +0100
Subject: [PATCH 10/16] Makefile.am: use Android SDK build-tools 27.0.0

---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 39bd18011..e4e29ac70 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -292,7 +292,7 @@ clean-local:
 libmpd.so: $(filter %.a,$(src_mpd_LDADD)) libmain.a
 	$(AM_V_CXXLD)$(CXXLD) -shared -Wl,--no-undefined,-shared,-Bsymbolic -llog -lz -o $@ $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) src/libmain_a-Main.o $(src_mpd_LDADD) $(LIBS)
 
-ANDROID_SDK_BUILD_TOOLS_VERSION = 20.0.0
+ANDROID_SDK_BUILD_TOOLS_VERSION = 27.0.0
 ANDROID_SDK_PLATFORM = android-17
 
 ANDROID_BUILD_TOOLS_DIR = $(ANDROID_SDK)/build-tools/$(ANDROID_SDK_BUILD_TOOLS_VERSION)

From 3ca80a73367bfbf8531ab1f38b8ec1cf2a66703e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:19:46 +0100
Subject: [PATCH 11/16] util/RefCount, db/simple/Mount: remove obsolete libc++
 workarounds

No longer a problem with NDK r16.
---
 src/db/plugins/simple/Mount.cxx | 7 -------
 src/util/RefCount.hxx           | 5 -----
 2 files changed, 12 deletions(-)

diff --git a/src/db/plugins/simple/Mount.cxx b/src/db/plugins/simple/Mount.cxx
index c07b67abc..1945b74c6 100644
--- a/src/db/plugins/simple/Mount.cxx
+++ b/src/db/plugins/simple/Mount.cxx
@@ -25,13 +25,6 @@
 #include "db/Interface.hxx"
 #include "fs/Traits.hxx"
 
-#ifdef _LIBCPP_VERSION
-/* workaround for "error: incomplete type 'PlaylistInfo' used in type
-   trait expression" with libc++ version 3900 (from Android NDK
-   r13b) */
-#include "db/PlaylistInfo.hxx"
-#endif
-
 #include <string>
 
 struct PrefixedLightDirectory : LightDirectory {
diff --git a/src/util/RefCount.hxx b/src/util/RefCount.hxx
index 8faf839f1..a3466eb9a 100644
--- a/src/util/RefCount.hxx
+++ b/src/util/RefCount.hxx
@@ -42,11 +42,6 @@ class RefCount {
 	std::atomic_uint n;
 
 public:
-#ifndef _LIBCPP_VERSION
-	/* the "constexpr" is missing in libc++'s "atomic"
-	   implementation */
-	constexpr
-#endif
 	RefCount():n(1) {}
 
 	void Increment() {

From e8975942eca329727181f4b16077b5cf375fd8f8 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:38:10 +0100
Subject: [PATCH 12/16] Makefile.am: link libicu.a before libutil.a

libicu.a depends on libutil.a.
---
 Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index e4e29ac70..5e468aa42 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -61,8 +61,8 @@ src_mpd_LDADD = \
 	libnet.a \
 	$(FS_LIBS) \
 	libsystem.a \
-	libutil.a \
 	$(ICU_LDADD) \
+	libutil.a \
 	$(SYSTEMD_DAEMON_LIBS)
 
 src_mpd_SOURCES = \

From 38d56dddf1d5e13b897c4b222205d2d4a8069b01 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:49:50 +0100
Subject: [PATCH 13/16] lib/icu/Compare: allow copying

---
 src/lib/icu/Compare.hxx | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/lib/icu/Compare.hxx b/src/lib/icu/Compare.hxx
index 9ee2e6848..d38026508 100644
--- a/src/lib/icu/Compare.hxx
+++ b/src/lib/icu/Compare.hxx
@@ -37,6 +37,18 @@ public:
 
 	explicit IcuCompare(const char *needle) noexcept;
 
+	IcuCompare(const IcuCompare &src) noexcept
+		:needle(src
+			? AllocatedString<>::Duplicate(src.needle.c_str())
+			: nullptr) {}
+
+	IcuCompare &operator=(const IcuCompare &src) noexcept {
+		needle = src
+			? AllocatedString<>::Duplicate(src.needle.c_str())
+			: nullptr;
+		return *this;
+	}
+
 	IcuCompare(IcuCompare &&) = default;
 	IcuCompare &operator=(IcuCompare &&) = default;
 

From 386688b87ac87200ed6c68b0b5273ad7151e8a0a Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:35:36 +0100
Subject: [PATCH 14/16] SongFilter: use std::string instead of AllocatedString

---
 src/SongFilter.cxx | 2 +-
 src/SongFilter.hxx | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx
index 4c3e746b1..a42f15ff4 100644
--- a/src/SongFilter.cxx
+++ b/src/SongFilter.cxx
@@ -59,7 +59,7 @@ locate_parse_type(const char *str) noexcept
 
 SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
 	:tag(_tag),
-	 value(AllocatedString<>::Duplicate(_value)),
+	 value(_value),
 	 fold_case(_fold_case ? IcuCompare(value.c_str()) : IcuCompare())
 {
 }
diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index ec8317879..e7f4da9ab 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -21,9 +21,9 @@
 #define MPD_SONG_FILTER_HXX
 
 #include "lib/icu/Compare.hxx"
-#include "util/AllocatedString.hxx"
 #include "Compiler.h"
 
+#include <string>
 #include <list>
 
 #include <stdint.h>
@@ -49,7 +49,7 @@ public:
 	class Item {
 		uint8_t tag;
 
-		AllocatedString<> value;
+		std::string value;
 
 		/**
 		 * This value is only set if case folding is enabled.

From ed2354cd9dd8169985ba6d6cd89ceb61a4048346 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:39:32 +0100
Subject: [PATCH 15/16] SongFilter: allow copying items

---
 src/SongFilter.hxx | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index e7f4da9ab..d102db94f 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -66,11 +66,6 @@ public:
 		Item(unsigned tag, const char *value, bool fold_case=false);
 		Item(unsigned tag, time_t time);
 
-		Item(const Item &other) = delete;
-		Item(Item &&) = default;
-
-		Item &operator=(const Item &other) = delete;
-
 		unsigned GetTag() const {
 			return tag;
 		}

From 8376578921c344a584b604657cc7275be804551d Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 19 Jan 2018 23:35:05 +0100
Subject: [PATCH 16/16] db/simple/Mount: drop mount point prefix from
 LOCATE_TAG_BASE_TYPE

Fixes search within mount points, resulting in error "No such
directory".

Closes #190
---
 NEWS                            |  2 ++
 src/SongFilter.cxx              | 32 ++++++++++++++++++++++++++++++++
 src/SongFilter.hxx              |  7 +++++++
 src/db/plugins/simple/Mount.cxx | 12 ++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/NEWS b/NEWS
index f5182a945..2836e984e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.20.16 (not yet released)
+* database
+  - simple: fix search within mount points
 * fix crash in debug build on Haiku and other operating systems
 
 ver 0.20.15 (2018/01/05)
diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx
index a42f15ff4..c0e0a2edd 100644
--- a/src/SongFilter.cxx
+++ b/src/SongFilter.cxx
@@ -24,6 +24,8 @@
 #include "tag/Tag.hxx"
 #include "util/ConstBuffer.hxx"
 #include "util/StringAPI.hxx"
+#include "util/StringCompare.hxx"
+#include "util/StringView.hxx"
 #include "util/ASCII.hxx"
 #include "util/TimeParser.hxx"
 #include "util/UriUtil.hxx"
@@ -274,3 +276,33 @@ SongFilter::GetBase() const noexcept
 
 	return nullptr;
 }
+
+SongFilter
+SongFilter::WithoutBasePrefix(const char *_prefix) const noexcept
+{
+	const StringView prefix(_prefix);
+	SongFilter result;
+
+	for (const auto &i : items) {
+		if (i.GetTag() == LOCATE_TAG_BASE_TYPE) {
+			const char *s = StringAfterPrefix(i.GetValue(), prefix);
+			if (s != nullptr) {
+				if (*s == 0)
+					continue;
+
+				if (*s == '/') {
+					++s;
+
+					if (*s != 0)
+						result.items.emplace_back(LOCATE_TAG_BASE_TYPE, s);
+
+					continue;
+				}
+			}
+		}
+
+		result.items.emplace_back(i);
+	}
+
+	return result;
+}
diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index d102db94f..f0fa73635 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -152,6 +152,13 @@ public:
 	 */
 	gcc_pure
 	const char *GetBase() const noexcept;
+
+	/**
+	 * Create a copy of the filter with the given prefix stripped
+	 * from all #LOCATE_TAG_BASE_TYPE items.  This is used to
+	 * filter songs in mounted databases.
+	 */
+	SongFilter WithoutBasePrefix(const char *prefix) const noexcept;
 };
 
 /**
diff --git a/src/db/plugins/simple/Mount.cxx b/src/db/plugins/simple/Mount.cxx
index 1945b74c6..22db95f46 100644
--- a/src/db/plugins/simple/Mount.cxx
+++ b/src/db/plugins/simple/Mount.cxx
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "Mount.hxx"
 #include "PrefixedLightSong.hxx"
+#include "SongFilter.hxx"
 #include "db/Selection.hxx"
 #include "db/LightDirectory.hxx"
 #include "db/Interface.hxx"
@@ -86,5 +87,16 @@ WalkMount(const char *base, const Database &db,
 		vp = std::bind(PrefixVisitPlaylist,
 			       base, std::ref(visit_playlist), _1, _2);
 
+	SongFilter prefix_filter;
+
+	if (base != nullptr && filter != nullptr) {
+		/* if the SongFilter contains a LOCATE_TAG_BASE_TYPE
+		   item, copy the SongFilter and drop the mount point
+		   from the filter, because the mounted database
+		   doesn't know its own location within MPD's VFS */
+		prefix_filter = filter->WithoutBasePrefix(base);
+		filter = &prefix_filter;
+	}
+
 	db.Visit(DatabaseSelection(uri, recursive, filter), vd, vs, vp);
 }