db/Song: translate relative "real_uri" paths

This commit is contained in:
Max Kellermann 2019-09-06 23:10:32 +02:00
parent 9caf90f74f
commit 91c1274ac6

View File

@ -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 <assert.h>
@ -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;