aboutsummaryrefslogtreecommitdiffstats
path: root/src/Mapper.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-07 23:34:29 +0100
committerMax Kellermann <max@duempel.org>2014-02-07 23:34:29 +0100
commit6798af52b69a9c6712f79989349a5fce929cd874 (patch)
tree7d897a0d85f24499d6762c716fd5e37abda3331c /src/Mapper.cxx
parent4d5ebafa6dd1ed5d40e5e7f6b86aae1d828341cf (diff)
downloadmpd-6798af52b69a9c6712f79989349a5fce929cd874.tar.gz
mpd-6798af52b69a9c6712f79989349a5fce929cd874.tar.xz
mpd-6798af52b69a9c6712f79989349a5fce929cd874.zip
Mapper: obtain music directory from Storage
Eliminate duplicate variable.
Diffstat (limited to 'src/Mapper.cxx')
-rw-r--r--src/Mapper.cxx46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/Mapper.cxx b/src/Mapper.cxx
index f97cc3f9c..7baad9459 100644
--- a/src/Mapper.cxx
+++ b/src/Mapper.cxx
@@ -28,36 +28,20 @@
#include "fs/Charset.hxx"
#include "fs/CheckFile.hxx"
-#include <assert.h>
-
#ifdef ENABLE_DATABASE
-
-/**
- * The absolute path of the music directory encoded in the filesystem
- * character set.
- */
-static AllocatedPath music_dir_fs = AllocatedPath::Null();
-
+#include "storage/StorageInterface.hxx"
+#include "Instance.hxx"
+#include "Main.hxx"
#endif
+#include <assert.h>
+
/**
* The absolute path of the playlist directory encoded in the
* filesystem character set.
*/
static AllocatedPath playlist_dir_fs = AllocatedPath::Null();
-#ifdef ENABLE_DATABASE
-
-static void
-mapper_set_music_dir(AllocatedPath &&path)
-{
- assert(!path.IsNull());
-
- music_dir_fs = std::move(path);
-}
-
-#endif
-
static void
mapper_set_playlist_dir(AllocatedPath &&path)
{
@@ -69,15 +53,8 @@ mapper_set_playlist_dir(AllocatedPath &&path)
}
void
-mapper_init(AllocatedPath &&_music_dir, AllocatedPath &&_playlist_dir)
+mapper_init(AllocatedPath &&_playlist_dir)
{
-#ifdef ENABLE_DATABASE
- if (!_music_dir.IsNull())
- mapper_set_music_dir(std::move(_music_dir));
-#else
- (void)_music_dir;
-#endif
-
if (!_playlist_dir.IsNull())
mapper_set_playlist_dir(std::move(_playlist_dir));
}
@@ -94,6 +71,10 @@ map_uri_fs(const char *uri)
assert(uri != nullptr);
assert(*uri != '/');
+ if (instance->storage == nullptr)
+ return AllocatedPath::Null();
+
+ const auto music_dir_fs = instance->storage->MapFS("");
if (music_dir_fs.IsNull())
return AllocatedPath::Null();
@@ -108,6 +89,13 @@ std::string
map_fs_to_utf8(const char *path_fs)
{
if (PathTraitsFS::IsSeparator(path_fs[0])) {
+ if (instance->storage == nullptr)
+ return std::string();
+
+ const auto music_dir_fs = instance->storage->MapFS("");
+ if (music_dir_fs.IsNull())
+ return std::string();
+
path_fs = music_dir_fs.RelativeFS(path_fs);
if (path_fs == nullptr || *path_fs == 0)
return std::string();