diff --git a/src/db/DatabaseSong.cxx b/src/db/DatabaseSong.cxx index 6eee88a2b..3e416829a 100644 --- a/src/db/DatabaseSong.cxx +++ b/src/db/DatabaseSong.cxx @@ -23,6 +23,8 @@ #include "song/LightSong.hxx" #include "storage/StorageInterface.hxx" #include "util/ScopeExit.hxx" +#include "util/UriExtract.hxx" +#include "util/UriRelative.hxx" #include @@ -32,9 +34,19 @@ DatabaseDetachSong(const Storage *storage, const LightSong &song) noexcept DetachedSong detached(song); assert(detached.IsInDatabase()); - if (!detached.HasRealURI() && storage != nullptr) { - const auto uri = song.GetURI(); - detached.SetRealURI(storage->MapUTF8(uri.c_str())); + if (storage != nullptr) { + if (!detached.HasRealURI()) { + const auto uri = song.GetURI(); + detached.SetRealURI(storage->MapUTF8(uri.c_str())); + } else if (uri_is_relative_path(detached.GetRealURI())) { + /* if the "RealURI" is relative, translate it + using the song's "URI" attribute, because + it's assumed to be relative to it */ + const auto real_uri = + uri_apply_relative(detached.GetRealURI(), + song.GetURI()); + detached.SetRealURI(storage->MapUTF8(real_uri.c_str())); + } } return detached;