summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2021-08-05 20:06:15 +0200
committerMax Kellermann <max@musicpd.org>2021-08-05 20:09:06 +0200
commit1761fb14af6c810735fa456cd19274681a89a1c9 (patch)
treee0ed1ac71a2eedc7e34e76ea097e31815a25ce7a
parentef2fc4e6f618fad0823eb68943e132ec565aeafc (diff)
fs/Traits: add PathTraitsUTF8::IsAbsoluteOrHasScheme()
-rw-r--r--src/fs/Traits.cxx7
-rw-r--r--src/fs/Traits.hxx7
-rw-r--r--src/playlist/PlaylistSong.cxx4
-rw-r--r--src/song/DetachedSong.cxx2
4 files changed, 17 insertions, 3 deletions
diff --git a/src/fs/Traits.cxx b/src/fs/Traits.cxx
index 35d7fa1fd..32f65105a 100644
--- a/src/fs/Traits.cxx
+++ b/src/fs/Traits.cxx
@@ -19,6 +19,7 @@
#include "Traits.hxx"
#include "util/StringCompare.hxx"
+#include "util/UriExtract.hxx"
#include <string.h>
@@ -220,6 +221,12 @@ PathTraitsUTF8::Build(string_view a, string_view b) noexcept
return BuildPathImpl<PathTraitsUTF8>(a, b);
}
+bool
+PathTraitsUTF8::IsAbsoluteOrHasScheme(const_pointer p) noexcept
+{
+ return IsAbsolute(p) || uri_has_scheme(p);
+}
+
PathTraitsUTF8::const_pointer
PathTraitsUTF8::GetBase(const_pointer p) noexcept
{
diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx
index a5495a29f..f88cf33ac 100644
--- a/src/fs/Traits.hxx
+++ b/src/fs/Traits.hxx
@@ -274,6 +274,13 @@ struct PathTraitsUTF8 {
return IsSeparator(*p);
}
+ /**
+ * Is this any kind of absolute URI? (Unlike IsAbsolute(),
+ * this includes URIs/URLs with a scheme)
+ */
+ [[gnu::pure]] [[gnu::nonnull]]
+ static bool IsAbsoluteOrHasScheme(const_pointer p) noexcept;
+
gcc_pure gcc_nonnull_all
static bool IsSpecialFilename(const_pointer name) noexcept {
return (name[0] == '.' && name[1] == 0) ||
diff --git a/src/playlist/PlaylistSong.cxx b/src/playlist/PlaylistSong.cxx
index e03d580db..135e66393 100644
--- a/src/playlist/PlaylistSong.cxx
+++ b/src/playlist/PlaylistSong.cxx
@@ -92,8 +92,8 @@ playlist_check_translate_song(DetachedSong &song, std::string_view base_uri,
}
#endif
- if (base_uri.data() != nullptr && !uri_has_scheme(uri) &&
- !PathTraitsUTF8::IsAbsolute(uri))
+ if (base_uri.data() != nullptr &&
+ !PathTraitsUTF8::IsAbsoluteOrHasScheme(uri))
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
return playlist_check_load_song(song, loader);
diff --git a/src/song/DetachedSong.cxx b/src/song/DetachedSong.cxx
index 5ba67d097..e94f5bc72 100644
--- a/src/song/DetachedSong.cxx
+++ b/src/song/DetachedSong.cxx
@@ -60,7 +60,7 @@ DetachedSong::IsInDatabase() const noexcept
GetRealURI() is never relative */
const char *_uri = GetURI();
- return !uri_has_scheme(_uri) && !PathTraitsUTF8::IsAbsolute(_uri);
+ return !PathTraitsUTF8::IsAbsoluteOrHasScheme(_uri);
}
SignedSongTime