diff options
Diffstat (limited to 'src/Mapper.cxx')
-rw-r--r-- | src/Mapper.cxx | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/Mapper.cxx b/src/Mapper.cxx index cbe45daa0..ebcab91bf 100644 --- a/src/Mapper.cxx +++ b/src/Mapper.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -23,8 +23,10 @@ #include "config.h" #include "Mapper.hxx" -#include "Directory.hxx" -#include "Song.hxx" +#include "DetachedSong.hxx" +#include "db/Directory.hxx" +#include "db/Song.hxx" +#include "db/LightSong.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" #include "fs/Charset.hxx" @@ -36,9 +38,7 @@ #include <assert.h> #include <string.h> #include <sys/stat.h> -#include <unistd.h> #include <errno.h> -#include <dirent.h> static constexpr Domain mapper_domain("mapper"); @@ -150,7 +150,7 @@ map_to_relative_path(const char *path_utf8) return !music_dir_utf8.empty() && memcmp(path_utf8, music_dir_utf8.c_str(), music_dir_utf8_length) == 0 && - PathTraits::IsSeparatorUTF8(path_utf8[music_dir_utf8_length]) + PathTraitsUTF8::IsSeparator(path_utf8[music_dir_utf8_length]) ? path_utf8 + music_dir_utf8_length + 1 : path_utf8; } @@ -218,23 +218,41 @@ map_detached_song_fs(const char *uri_utf8) return AllocatedPath::Build(music_dir_fs, uri_fs); } +DetachedSong +map_song_detach(const LightSong &song) +{ + DetachedSong detached(song); + + if (detached.IsInDatabase() && !detached.HasRealURI()) { + const auto uri = song.GetURI(); + detached.SetRealURI(PathTraitsUTF8::Build(music_dir_utf8.c_str(), + uri.c_str())); + } + + return detached; +} + AllocatedPath map_song_fs(const Song &song) { - assert(song.IsFile()); + return song.parent == nullptr + ? map_detached_song_fs(song.uri) + : map_directory_child_fs(*song.parent, song.uri); +} - if (song.IsInDatabase()) - return song.IsDetached() - ? map_detached_song_fs(song.uri) - : map_directory_child_fs(*song.parent, song.uri); +AllocatedPath +map_song_fs(const DetachedSong &song) +{ + if (song.IsAbsoluteFile()) + return AllocatedPath::FromUTF8(song.GetRealURI()); else - return AllocatedPath::FromUTF8(song.uri); + return map_uri_fs(song.GetURI()); } std::string map_fs_to_utf8(const char *path_fs) { - if (PathTraits::IsSeparatorFS(path_fs[0])) { + if (PathTraitsFS::IsSeparator(path_fs[0])) { path_fs = music_dir_fs.RelativeFS(path_fs); if (path_fs == nullptr || *path_fs == 0) return std::string(); |