db/update: pass filenames as std::string_view

This commit is contained in:
Max Kellermann 2023-04-30 08:23:11 +02:00
parent 434bcb08ee
commit f2a4ae15aa
3 changed files with 12 additions and 13 deletions

View File

@ -14,7 +14,7 @@
#include "archive/ArchivePlugin.hxx" #include "archive/ArchivePlugin.hxx"
#include "archive/ArchiveFile.hxx" #include "archive/ArchiveFile.hxx"
#include "archive/ArchiveVisitor.hxx" #include "archive/ArchiveVisitor.hxx"
#include "util/StringCompare.hxx" #include "util/StringSplit.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <exception> #include <exception>
@ -37,19 +37,18 @@ LockFindSong(Directory &directory, std::string_view name) noexcept
void void
UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory, UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
const char *name) noexcept std::string_view name) noexcept
{ {
const char *tmp = std::strchr(name, '/'); const auto [child_name, rest] = Split(name, '/');
if (tmp) { if (rest.data() != nullptr) {
const std::string_view child_name(name, tmp - name);
//add dir is not there already //add dir is not there already
Directory *subdir = LockMakeChild(directory, child_name); Directory *subdir = LockMakeChild(directory, child_name);
subdir->device = DEVICE_INARCHIVE; subdir->device = DEVICE_INARCHIVE;
//create directories first //create directories first
UpdateArchiveTree(archive, *subdir, tmp + 1); UpdateArchiveTree(archive, *subdir, rest);
} else { } else {
if (StringIsEmpty(name)) { if (name.empty()) {
LogWarning(update_domain, LogWarning(update_domain,
"archive returned directory only"); "archive returned directory only");
return; return;

View File

@ -16,7 +16,7 @@
inline void inline void
UpdateWalk::UpdateSongFile2(Directory &directory, UpdateWalk::UpdateSongFile2(Directory &directory,
const char *name, std::string_view suffix, std::string_view name, std::string_view suffix,
const StorageFileInfo &info) noexcept const StorageFileInfo &info) noexcept
try { try {
Song *song; Song *song;
@ -83,7 +83,7 @@ try {
bool bool
UpdateWalk::UpdateSongFile(Directory &directory, UpdateWalk::UpdateSongFile(Directory &directory,
const char *name, std::string_view suffix, std::string_view name, std::string_view suffix,
const StorageFileInfo &info) noexcept const StorageFileInfo &info) noexcept
{ {
if (!decoder_plugins_supports_suffix(suffix)) if (!decoder_plugins_supports_suffix(suffix))

View File

@ -79,11 +79,11 @@ private:
void PurgeDanglingFromPlaylists(Directory &directory) noexcept; void PurgeDanglingFromPlaylists(Directory &directory) noexcept;
void UpdateSongFile2(Directory &directory, void UpdateSongFile2(Directory &directory,
const char *name, std::string_view suffix, std::string_view name, std::string_view suffix,
const StorageFileInfo &info) noexcept; const StorageFileInfo &info) noexcept;
bool UpdateSongFile(Directory &directory, bool UpdateSongFile(Directory &directory,
const char *name, std::string_view suffix, std::string_view name, std::string_view suffix,
const StorageFileInfo &info) noexcept; const StorageFileInfo &info) noexcept;
bool UpdateContainerFile(Directory &directory, bool UpdateContainerFile(Directory &directory,
@ -93,7 +93,7 @@ private:
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
void UpdateArchiveTree(ArchiveFile &archive, Directory &parent, void UpdateArchiveTree(ArchiveFile &archive, Directory &parent,
const char *name) noexcept; std::string_view name) noexcept;
bool UpdateArchiveFile(Directory &directory, bool UpdateArchiveFile(Directory &directory,
std::string_view name, std::string_view suffix, std::string_view name, std::string_view suffix,
@ -106,7 +106,7 @@ private:
#else #else
bool UpdateArchiveFile([[maybe_unused]] Directory &directory, bool UpdateArchiveFile([[maybe_unused]] Directory &directory,
[[maybe_unused]] const char *name, [[maybe_unused]] std::string_view name,
[[maybe_unused]] std::string_view suffix, [[maybe_unused]] std::string_view suffix,
[[maybe_unused]] const StorageFileInfo &info) noexcept { [[maybe_unused]] const StorageFileInfo &info) noexcept {
return false; return false;