storage/Interface: convert URI parameters to std::string_view

This commit is contained in:
Max Kellermann 2020-04-03 16:22:39 +02:00
parent 0080eee857
commit a98d627c0b
12 changed files with 115 additions and 128 deletions

View File

@ -42,11 +42,13 @@ LocateFileUri(const char *uri, const Client *client
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (storage != nullptr) { if (storage != nullptr) {
const char *suffix = storage->MapToRelativeUTF8(uri); const auto suffix = storage->MapToRelativeUTF8(uri);
if (suffix != nullptr) if (suffix.data() != nullptr)
/* this path was relative to the music /* this path was relative to the music
directory */ directory */
return LocatedUri(LocatedUri::Type::RELATIVE, suffix); // TODO: don't use suffix.data() (ok for now because we know it's null-terminated)
return LocatedUri(LocatedUri::Type::RELATIVE,
suffix.data());
} }
#endif #endif
@ -80,9 +82,11 @@ LocateAbsoluteUri(UriPluginKind kind, const char *uri
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (storage != nullptr) { if (storage != nullptr) {
const char *suffix = storage->MapToRelativeUTF8(uri); const auto suffix = storage->MapToRelativeUTF8(uri);
if (suffix != nullptr) if (suffix.data() != nullptr)
return LocatedUri(LocatedUri::Type::RELATIVE, suffix); // TODO: don't use suffix.data() (ok for now because we know it's null-terminated)
return LocatedUri(LocatedUri::Type::RELATIVE,
suffix.data());
} }
#endif #endif

View File

@ -54,11 +54,11 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs) const
{ {
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (storage != nullptr) { if (storage != nullptr) {
const char *suffix = storage->MapToRelativeUTF8(path_utf8); const auto suffix = storage->MapToRelativeUTF8(path_utf8);
if (suffix != nullptr) if (suffix.data() != nullptr)
/* this path was relative to the music /* this path was relative to the music
directory - obtain it from the database */ directory - obtain it from the database */
return LoadFromDatabase(suffix); return LoadFromDatabase(std::string(suffix).c_str());
} }
#endif #endif

View File

@ -260,9 +260,9 @@ UpdateWalk::SkipSymlink(const Directory *directory,
if (target_utf8.empty()) if (target_utf8.empty())
return true; return true;
const char *relative = auto relative =
storage.MapToRelativeUTF8(target_utf8.c_str()); storage.MapToRelativeUTF8(target_utf8.c_str());
return relative != nullptr return relative.data() != nullptr
? !config.follow_inside_symlinks ? !config.follow_inside_symlinks
: !config.follow_outside_symlinks; : !config.follow_outside_symlinks;
} }

View File

@ -83,24 +83,19 @@ CompositeDirectoryReader::GetInfo(bool follow)
} }
static std::string_view static std::string_view
NextSegment(const char *&uri_r) NextSegment(std::string_view &uri_r) noexcept
{ {
const char *uri = uri_r; StringView uri(uri_r);
const char *slash = strchr(uri, '/'); auto s = uri.Split('/');
if (slash == nullptr) { uri_r = s.second;
uri_r += strlen(uri); return s.first;
return uri;
} else {
uri_r = slash + 1;
return std::string_view(uri, slash - uri);
}
} }
const CompositeStorage::Directory * const CompositeStorage::Directory *
CompositeStorage::Directory::Find(const char *uri) const noexcept CompositeStorage::Directory::Find(std::string_view uri) const noexcept
{ {
const Directory *directory = this; const Directory *directory = this;
while (*uri != 0) { while (!uri.empty()) {
const auto name = NextSegment(uri); const auto name = NextSegment(uri);
auto i = directory->children.find(name); auto i = directory->children.find(name);
if (i == directory->children.end()) if (i == directory->children.end())
@ -113,10 +108,10 @@ CompositeStorage::Directory::Find(const char *uri) const noexcept
} }
CompositeStorage::Directory & CompositeStorage::Directory &
CompositeStorage::Directory::Make(const char *uri) CompositeStorage::Directory::Make(std::string_view uri)
{ {
Directory *directory = this; Directory *directory = this;
while (*uri != 0) { while (!uri.empty()) {
auto name = NextSegment(uri); auto name = NextSegment(uri);
auto i = directory->children.emplace(std::move(name), auto i = directory->children.emplace(std::move(name),
Directory()); Directory());
@ -137,9 +132,9 @@ CompositeStorage::Directory::Unmount() noexcept
} }
bool bool
CompositeStorage::Directory::Unmount(const char *uri) noexcept CompositeStorage::Directory::Unmount(std::string_view uri) noexcept
{ {
if (StringIsEmpty(uri)) if (uri.empty())
return Unmount(); return Unmount();
const auto name = NextSegment(uri); const auto name = NextSegment(uri);
@ -157,11 +152,11 @@ CompositeStorage::Directory::Unmount(const char *uri) noexcept
bool bool
CompositeStorage::Directory::MapToRelativeUTF8(std::string &buffer, CompositeStorage::Directory::MapToRelativeUTF8(std::string &buffer,
const char *uri) const noexcept std::string_view uri) const noexcept
{ {
if (storage != nullptr) { if (storage != nullptr) {
const char *result = storage->MapToRelativeUTF8(uri); auto result = storage->MapToRelativeUTF8(uri);
if (result != nullptr) { if (result.data() != nullptr) {
buffer = result; buffer = result;
return true; return true;
} }
@ -191,12 +186,12 @@ CompositeStorage::CompositeStorage() noexcept
CompositeStorage::~CompositeStorage() = default; CompositeStorage::~CompositeStorage() = default;
Storage * Storage *
CompositeStorage::GetMount(const char *uri) noexcept CompositeStorage::GetMount(std::string_view uri) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto result = FindStorage(uri); auto result = FindStorage(uri);
if (*result.uri != 0) if (!result.uri.empty())
/* not a mount point */ /* not a mount point */
return nullptr; return nullptr;
@ -221,12 +216,12 @@ CompositeStorage::Unmount(const char *uri)
} }
CompositeStorage::FindResult CompositeStorage::FindResult
CompositeStorage::FindStorage(const char *uri) const noexcept CompositeStorage::FindStorage(std::string_view uri) const noexcept
{ {
FindResult result{&root, uri}; FindResult result{&root, uri};
const Directory *directory = &root; const Directory *directory = &root;
while (*uri != 0) { while (!uri.empty()) {
const auto name = NextSegment(uri); const auto name = NextSegment(uri);
auto i = directory->children.find(name); auto i = directory->children.find(name);
@ -242,7 +237,7 @@ CompositeStorage::FindStorage(const char *uri) const noexcept
} }
StorageFileInfo StorageFileInfo
CompositeStorage::GetInfo(const char *uri, bool follow) CompositeStorage::GetInfo(std::string_view uri, bool follow)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
@ -268,7 +263,7 @@ CompositeStorage::GetInfo(const char *uri, bool follow)
} }
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
CompositeStorage::OpenDirectory(const char *uri) CompositeStorage::OpenDirectory(std::string_view uri)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
@ -295,7 +290,7 @@ CompositeStorage::OpenDirectory(const char *uri)
} }
std::string std::string
CompositeStorage::MapUTF8(const char *uri) const noexcept CompositeStorage::MapUTF8(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
@ -307,7 +302,7 @@ CompositeStorage::MapUTF8(const char *uri) const noexcept
} }
AllocatedPath AllocatedPath
CompositeStorage::MapFS(const char *uri) const noexcept CompositeStorage::MapFS(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
@ -318,19 +313,19 @@ CompositeStorage::MapFS(const char *uri) const noexcept
return f.directory->storage->MapFS(f.uri); return f.directory->storage->MapFS(f.uri);
} }
const char * std::string_view
CompositeStorage::MapToRelativeUTF8(const char *uri) const noexcept CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (root.storage != nullptr) { if (root.storage != nullptr) {
const char *result = root.storage->MapToRelativeUTF8(uri); auto result = root.storage->MapToRelativeUTF8(uri);
if (result != nullptr) if (result.data() != nullptr)
return result; return result;
} }
if (!root.MapToRelativeUTF8(relative_buffer, uri)) if (!root.MapToRelativeUTF8(relative_buffer, uri))
return nullptr; return nullptr;
return relative_buffer.c_str(); return relative_buffer;
} }

View File

@ -57,21 +57,21 @@ class CompositeStorage final : public Storage {
} }
gcc_pure gcc_pure
const Directory *Find(const char *uri) const noexcept; const Directory *Find(std::string_view uri) const noexcept;
Directory &Make(const char *uri); Directory &Make(std::string_view uri);
bool Unmount() noexcept; bool Unmount() noexcept;
bool Unmount(const char *uri) noexcept; bool Unmount(std::string_view uri) noexcept;
gcc_pure gcc_pure
bool MapToRelativeUTF8(std::string &buffer, bool MapToRelativeUTF8(std::string &buffer,
const char *uri) const noexcept; std::string_view uri) const noexcept;
}; };
struct FindResult { struct FindResult {
const Directory *directory; const Directory *directory;
const char *uri; std::string_view uri;
}; };
/** /**
@ -98,7 +98,7 @@ public:
* value is being used. * value is being used.
*/ */
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
Storage *GetMount(const char *uri) noexcept; Storage *GetMount(std::string_view uri) noexcept;
/** /**
* Call the given function for each mounted storage, including * Call the given function for each mounted storage, including
@ -116,15 +116,15 @@ public:
bool Unmount(const char *uri); bool Unmount(const char *uri);
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri, bool follow) override; StorageFileInfo GetInfo(std::string_view uri, bool follow) override;
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri) override; std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri) override;
std::string MapUTF8(const char *uri) const noexcept override; std::string MapUTF8(std::string_view uri) const noexcept override;
AllocatedPath MapFS(const char *uri) const noexcept override; AllocatedPath MapFS(std::string_view uri) const noexcept override;
const char *MapToRelativeUTF8(const char *uri) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri) const noexcept override;
private: private:
template<typename T> template<typename T>
@ -155,7 +155,7 @@ private:
* the URI was used). * the URI was used).
*/ */
gcc_pure gcc_pure
FindResult FindStorage(const char *uri) const noexcept; FindResult FindStorage(std::string_view uri) const noexcept;
const char *MapToRelativeUTF8(const Directory &directory, const char *MapToRelativeUTF8(const Directory &directory,
const char *uri) const; const char *uri) const;

View File

@ -22,7 +22,7 @@
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
AllocatedPath AllocatedPath
Storage::MapFS([[maybe_unused]] const char *uri_utf8) const noexcept Storage::MapFS([[maybe_unused]] std::string_view uri_utf8) const noexcept
{ {
return nullptr; return nullptr;
} }

View File

@ -52,18 +52,18 @@ public:
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
virtual StorageFileInfo GetInfo(const char *uri_utf8, bool follow) = 0; virtual StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) = 0;
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) = 0; virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) = 0;
/** /**
* Map the given relative URI to an absolute URI. * Map the given relative URI to an absolute URI.
*/ */
gcc_pure gcc_pure
virtual std::string MapUTF8(const char *uri_utf8) const noexcept = 0; virtual std::string MapUTF8(std::string_view uri_utf8) const noexcept = 0;
/** /**
* Map the given relative URI to a local file path. Returns * Map the given relative URI to a local file path. Returns
@ -71,7 +71,7 @@ public:
* support local files. * support local files.
*/ */
gcc_pure gcc_pure
virtual AllocatedPath MapFS(const char *uri_utf8) const noexcept; virtual AllocatedPath MapFS(std::string_view uri_utf8) const noexcept;
gcc_pure gcc_pure
AllocatedPath MapChildFS(std::string_view uri_utf8, AllocatedPath MapChildFS(std::string_view uri_utf8,
@ -83,7 +83,7 @@ public:
* string); if not, returns nullptr. * string); if not, returns nullptr.
*/ */
gcc_pure gcc_pure
virtual const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept = 0; virtual std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept = 0;
}; };
#endif #endif

View File

@ -57,29 +57,27 @@ public:
curl(_loop) {} curl(_loop) {}
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri_utf8, bool follow) override; StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) override;
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) override; std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) override;
std::string MapUTF8(const char *uri_utf8) const noexcept override; std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
}; };
std::string std::string
CurlStorage::MapUTF8(const char *uri_utf8) const noexcept CurlStorage::MapUTF8(std::string_view uri_utf8) const noexcept
{ {
assert(uri_utf8 != nullptr); if (uri_utf8.empty())
if (StringIsEmpty(uri_utf8))
return base; return base;
std::string path_esc = CurlEscapeUriPath(uri_utf8); std::string path_esc = CurlEscapeUriPath(uri_utf8);
return PathTraitsUTF8::Build(base, path_esc); return PathTraitsUTF8::Build(base, path_esc);
} }
const char * std::string_view
CurlStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept CurlStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base, return PathTraitsUTF8::Relative(base,
CurlUnescape(uri_utf8).c_str()); CurlUnescape(uri_utf8).c_str());
@ -447,7 +445,7 @@ protected:
}; };
StorageFileInfo StorageFileInfo
CurlStorage::GetInfo(const char *uri_utf8, [[maybe_unused]] bool follow) CurlStorage::GetInfo(std::string_view uri_utf8, [[maybe_unused]] bool follow)
{ {
// TODO: escape the given URI // TODO: escape the given URI
@ -541,7 +539,7 @@ protected:
}; };
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
CurlStorage::OpenDirectory(const char *uri_utf8) CurlStorage::OpenDirectory(std::string_view uri_utf8)
{ {
std::string uri = MapUTF8(uri_utf8); std::string uri = MapUTF8(uri_utf8);

View File

@ -56,18 +56,18 @@ public:
} }
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri_utf8, bool follow) override; StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) override;
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) override; std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) override;
std::string MapUTF8(const char *uri_utf8) const noexcept override; std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
AllocatedPath MapFS(const char *uri_utf8) const noexcept override; AllocatedPath MapFS(std::string_view uri_utf8) const noexcept override;
const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
private: private:
AllocatedPath MapFSOrThrow(const char *uri_utf8) const; AllocatedPath MapFSOrThrow(std::string_view uri_utf8) const;
}; };
static StorageFileInfo static StorageFileInfo
@ -95,29 +95,27 @@ Stat(Path path, bool follow)
} }
std::string std::string
LocalStorage::MapUTF8(const char *uri_utf8) const noexcept LocalStorage::MapUTF8(std::string_view uri_utf8) const noexcept
{ {
assert(uri_utf8 != nullptr); if (uri_utf8.empty())
if (StringIsEmpty(uri_utf8))
return base_utf8; return base_utf8;
return PathTraitsUTF8::Build(base_utf8, uri_utf8); return PathTraitsUTF8::Build(base_utf8, uri_utf8);
} }
AllocatedPath AllocatedPath
LocalStorage::MapFSOrThrow(const char *uri_utf8) const LocalStorage::MapFSOrThrow(std::string_view uri_utf8) const
{ {
assert(uri_utf8 != nullptr); assert(uri_utf8 != nullptr);
if (StringIsEmpty(uri_utf8)) if (uri_utf8.empty())
return base_fs; return base_fs;
return base_fs / AllocatedPath::FromUTF8Throw(uri_utf8); return base_fs / AllocatedPath::FromUTF8Throw(uri_utf8);
} }
AllocatedPath AllocatedPath
LocalStorage::MapFS(const char *uri_utf8) const noexcept LocalStorage::MapFS(std::string_view uri_utf8) const noexcept
{ {
try { try {
return MapFSOrThrow(uri_utf8); return MapFSOrThrow(uri_utf8);
@ -126,20 +124,20 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept
} }
} }
const char * std::string_view
LocalStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept LocalStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base_utf8, uri_utf8); return PathTraitsUTF8::Relative(base_utf8, uri_utf8);
} }
StorageFileInfo StorageFileInfo
LocalStorage::GetInfo(const char *uri_utf8, bool follow) LocalStorage::GetInfo(std::string_view uri_utf8, bool follow)
{ {
return Stat(MapFSOrThrow(uri_utf8), follow); return Stat(MapFSOrThrow(uri_utf8), follow);
} }
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
LocalStorage::OpenDirectory(const char *uri_utf8) LocalStorage::OpenDirectory(std::string_view uri_utf8)
{ {
return std::make_unique<LocalDirectoryReader>(MapFSOrThrow(uri_utf8)); return std::make_unique<LocalDirectoryReader>(MapFSOrThrow(uri_utf8));
} }

View File

@ -86,13 +86,13 @@ public:
} }
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri_utf8, bool follow) override; StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) override;
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) override; std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) override;
std::string MapUTF8(const char *uri_utf8) const noexcept override; std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
/* virtual methods from NfsLease */ /* virtual methods from NfsLease */
void OnNfsConnectionReady() noexcept final { void OnNfsConnectionReady() noexcept final {
@ -216,10 +216,8 @@ private:
}; };
static std::string static std::string
UriToNfsPath(const char *_uri_utf8) UriToNfsPath(std::string_view _uri_utf8)
{ {
assert(_uri_utf8 != nullptr);
/* libnfs paths must begin with a slash */ /* libnfs paths must begin with a slash */
std::string uri_utf8("/"); std::string uri_utf8("/");
uri_utf8.append(_uri_utf8); uri_utf8.append(_uri_utf8);
@ -233,18 +231,16 @@ UriToNfsPath(const char *_uri_utf8)
} }
std::string std::string
NfsStorage::MapUTF8(const char *uri_utf8) const noexcept NfsStorage::MapUTF8(std::string_view uri_utf8) const noexcept
{ {
assert(uri_utf8 != nullptr); if (uri_utf8.empty())
if (StringIsEmpty(uri_utf8))
return base; return base;
return PathTraitsUTF8::Build(base, uri_utf8); return PathTraitsUTF8::Build(base, uri_utf8);
} }
const char * std::string_view
NfsStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept NfsStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base, uri_utf8); return PathTraitsUTF8::Relative(base, uri_utf8);
} }
@ -294,7 +290,7 @@ protected:
}; };
StorageFileInfo StorageFileInfo
NfsStorage::GetInfo(const char *uri_utf8, bool follow) NfsStorage::GetInfo(std::string_view uri_utf8, bool follow)
{ {
const std::string path = UriToNfsPath(uri_utf8); const std::string path = UriToNfsPath(uri_utf8);
@ -397,7 +393,7 @@ NfsListDirectoryOperation::CollectEntries(struct nfsdir *dir)
} }
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
NfsStorage::OpenDirectory(const char *uri_utf8) NfsStorage::OpenDirectory(std::string_view uri_utf8)
{ {
const std::string path = UriToNfsPath(uri_utf8); const std::string path = UriToNfsPath(uri_utf8);

View File

@ -64,28 +64,26 @@ public:
} }
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri_utf8, bool follow) override; StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) override;
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) override; std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) override;
std::string MapUTF8(const char *uri_utf8) const noexcept override; std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
}; };
std::string std::string
SmbclientStorage::MapUTF8(const char *uri_utf8) const noexcept SmbclientStorage::MapUTF8(std::string_view uri_utf8) const noexcept
{ {
assert(uri_utf8 != nullptr); if (uri_utf8.empty())
if (StringIsEmpty(uri_utf8))
return base; return base;
return PathTraitsUTF8::Build(base, uri_utf8); return PathTraitsUTF8::Build(base, uri_utf8);
} }
const char * std::string_view
SmbclientStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept SmbclientStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base, uri_utf8); return PathTraitsUTF8::Relative(base, uri_utf8);
} }
@ -117,14 +115,14 @@ GetInfo(const char *path)
} }
StorageFileInfo StorageFileInfo
SmbclientStorage::GetInfo(const char *uri_utf8, [[maybe_unused]] bool follow) SmbclientStorage::GetInfo(std::string_view uri_utf8, [[maybe_unused]] bool follow)
{ {
const std::string mapped = MapUTF8(uri_utf8); const std::string mapped = MapUTF8(uri_utf8);
return ::GetInfo(mapped.c_str()); return ::GetInfo(mapped.c_str());
} }
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
SmbclientStorage::OpenDirectory(const char *uri_utf8) SmbclientStorage::OpenDirectory(std::string_view uri_utf8)
{ {
std::string mapped = MapUTF8(uri_utf8); std::string mapped = MapUTF8(uri_utf8);

View File

@ -98,19 +98,19 @@ public:
} }
/* virtual methods from class Storage */ /* virtual methods from class Storage */
StorageFileInfo GetInfo(const char *uri_utf8, bool follow) override { StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) override {
MountWait(); MountWait();
return mounted_storage->GetInfo(uri_utf8, follow); return mounted_storage->GetInfo(uri_utf8, follow);
} }
std::unique_ptr<StorageDirectoryReader> OpenDirectory(const char *uri_utf8) override { std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) override {
MountWait(); MountWait();
return mounted_storage->OpenDirectory(uri_utf8); return mounted_storage->OpenDirectory(uri_utf8);
} }
std::string MapUTF8(const char *uri_utf8) const noexcept override; std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
AllocatedPath MapFS(const char *uri_utf8) const noexcept override { AllocatedPath MapFS(std::string_view uri_utf8) const noexcept override {
try { try {
const_cast<UdisksStorage *>(this)->MountWait(); const_cast<UdisksStorage *>(this)->MountWait();
} catch (...) { } catch (...) {
@ -120,7 +120,7 @@ public:
return mounted_storage->MapFS(uri_utf8); return mounted_storage->MapFS(uri_utf8);
} }
const char *MapToRelativeUTF8(const char *uri_utf8) const noexcept override; std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
private: private:
void SetMountPoint(Path mount_point); void SetMountPoint(Path mount_point);
@ -324,11 +324,9 @@ try {
} }
std::string std::string
UdisksStorage::MapUTF8(const char *uri_utf8) const noexcept UdisksStorage::MapUTF8(std::string_view uri_utf8) const noexcept
{ {
assert(uri_utf8 != nullptr); if (uri_utf8.empty())
if (StringIsEmpty(uri_utf8))
/* kludge for a special case: return the "udisks://" /* kludge for a special case: return the "udisks://"
URI if the parameter is an empty string to fix the URI if the parameter is an empty string to fix the
mount URIs in the state file */ mount URIs in the state file */
@ -344,8 +342,8 @@ UdisksStorage::MapUTF8(const char *uri_utf8) const noexcept
} }
} }
const char * std::string_view
UdisksStorage::MapToRelativeUTF8(const char *uri_utf8) const noexcept UdisksStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
{ {
return PathTraitsUTF8::Relative(base_uri, uri_utf8); return PathTraitsUTF8::Relative(base_uri, uri_utf8);
} }