playlist/Mapper: use Storage::OpenFile()

This commit is contained in:
Max Kellermann 2024-05-15 14:59:28 +02:00
parent 6dfdd8c1c2
commit 131dcce0a1
9 changed files with 19 additions and 15 deletions

View File

@ -26,16 +26,16 @@ class SongLoader {
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Database *const db; const Database *const db;
const Storage *const storage; Storage *const storage;
#endif #endif
public: public:
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
explicit SongLoader(const IClient &_client) noexcept; explicit SongLoader(const IClient &_client) noexcept;
SongLoader(const Database *_db, const Storage *_storage) noexcept SongLoader(const Database *_db, Storage *_storage) noexcept
:client(nullptr), db(_db), storage(_storage) {} :client(nullptr), db(_db), storage(_storage) {}
SongLoader(const IClient &_client, const Database *_db, SongLoader(const IClient &_client, const Database *_db,
const Storage *_storage) noexcept Storage *_storage) noexcept
:client(&_client), db(_db), storage(_storage) {} :client(&_client), db(_db), storage(_storage) {}
#else #else
explicit SongLoader(const IClient &_client) noexcept explicit SongLoader(const IClient &_client) noexcept
@ -45,7 +45,7 @@ public:
#endif #endif
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *GetStorage() const noexcept { Storage *GetStorage() const noexcept {
return storage; return storage;
} }
#endif #endif

View File

@ -99,7 +99,7 @@ Client::GetDatabaseOrThrow() const
return partition->instance.GetDatabaseOrThrow(); return partition->instance.GetDatabaseOrThrow();
} }
const Storage * Storage *
Client::GetStorage() const noexcept Client::GetStorage() const noexcept
{ {
return partition->instance.storage; return partition->instance.storage;

View File

@ -248,7 +248,7 @@ public:
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Database *GetDatabase() const noexcept override; const Database *GetDatabase() const noexcept override;
const Storage *GetStorage() const noexcept override; Storage *GetStorage() const noexcept override;
#endif // ENABLE_DATABASE #endif // ENABLE_DATABASE
private: private:

View File

@ -34,6 +34,6 @@ public:
virtual const Database *GetDatabase() const noexcept = 0; virtual const Database *GetDatabase() const noexcept = 0;
[[gnu::pure]] [[gnu::pure]]
virtual const Storage *GetStorage() const noexcept = 0; virtual Storage *GetStorage() const noexcept = 0;
#endif // ENABLE_DATABASE #endif // ENABLE_DATABASE
}; };

View File

@ -11,7 +11,7 @@
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_open_any(const LocatedUri &located_uri, playlist_open_any(const LocatedUri &located_uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, Storage *storage,
#endif #endif
Mutex &mutex) Mutex &mutex)
{ {

View File

@ -23,6 +23,6 @@ class Storage;
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_open_any(const LocatedUri &located_uri, playlist_open_any(const LocatedUri &located_uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, Storage *storage,
#endif #endif
Mutex &mutex); Mutex &mutex);

View File

@ -3,9 +3,12 @@
#include "PlaylistMapper.hxx" #include "PlaylistMapper.hxx"
#include "PlaylistFile.hxx" #include "PlaylistFile.hxx"
#include "PlaylistRegistry.hxx"
#include "PlaylistStream.hxx" #include "PlaylistStream.hxx"
#include "SongEnumerator.hxx" #include "SongEnumerator.hxx"
#include "Mapper.hxx" #include "Mapper.hxx"
#include "input/InputStream.hxx"
#include "input/WaitReady.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "storage/StorageInterface.hxx" #include "storage/StorageInterface.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
@ -33,7 +36,7 @@ playlist_open_in_playlist_dir(const char *uri, Mutex &mutex)
* Load a playlist from the configured music directory. * Load a playlist from the configured music directory.
*/ */
static std::unique_ptr<SongEnumerator> static std::unique_ptr<SongEnumerator>
playlist_open_in_storage(const char *uri, const Storage *storage, Mutex &mutex) playlist_open_in_storage(const char *uri, Storage *storage, Mutex &mutex)
{ {
assert(uri_safe_local(uri)); assert(uri_safe_local(uri));
@ -43,8 +46,9 @@ playlist_open_in_storage(const char *uri, const Storage *storage, Mutex &mutex)
if (const auto path = storage->MapFS(uri); !path.IsNull()) if (const auto path = storage->MapFS(uri); !path.IsNull())
return playlist_open_path(path, mutex); return playlist_open_path(path, mutex);
const auto uri2 = storage->MapUTF8(uri); auto is = storage->OpenFile(uri, mutex);
return playlist_open_remote(uri2.c_str(), mutex); LockWaitReady(*is);
return playlist_list_open_stream(std::move(is), uri);
} }
#endif #endif
@ -52,7 +56,7 @@ playlist_open_in_storage(const char *uri, const Storage *storage, Mutex &mutex)
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_mapper_open(const char *uri, playlist_mapper_open(const char *uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, Storage *storage,
#endif #endif
Mutex &mutex) Mutex &mutex)
{ {

View File

@ -22,6 +22,6 @@ class Storage;
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_mapper_open(const char *uri, playlist_mapper_open(const char *uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, Storage *storage,
#endif #endif
Mutex &mutex); Mutex &mutex);

View File

@ -123,7 +123,7 @@ public:
return reinterpret_cast<const Database *>(this); return reinterpret_cast<const Database *>(this);
} }
const Storage *GetStorage() const noexcept override { Storage *GetStorage() const noexcept override {
return ::storage; return ::storage;
} }
#endif // ENABLE_DATABASE #endif // ENABLE_DATABASE