From 1761fb14af6c810735fa456cd19274681a89a1c9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 5 Aug 2021 20:06:15 +0200 Subject: [PATCH] fs/Traits: add PathTraitsUTF8::IsAbsoluteOrHasScheme() --- src/fs/Traits.cxx | 7 +++++++ src/fs/Traits.hxx | 7 +++++++ src/playlist/PlaylistSong.cxx | 4 ++-- src/song/DetachedSong.cxx | 2 +- 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 @@ -220,6 +221,12 @@ PathTraitsUTF8::Build(string_view a, string_view b) noexcept return BuildPathImpl(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