db/simple/Song: allow LoadFile(), UpdateFile() to throw
Preparing to move logger calls out of lower-level libaries, and propagating error details to the caller instead.
This commit is contained in:
parent
6ee7d88af0
commit
3fc4da382e
@ -42,8 +42,7 @@
|
|||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
|
||||||
SongPtr
|
SongPtr
|
||||||
Song::LoadFile(Storage &storage, const char *path_utf8,
|
Song::LoadFile(Storage &storage, const char *path_utf8, Directory &parent)
|
||||||
Directory &parent) noexcept
|
|
||||||
{
|
{
|
||||||
assert(!uri_has_scheme(path_utf8));
|
assert(!uri_has_scheme(path_utf8));
|
||||||
assert(strchr(path_utf8, '\n') == nullptr);
|
assert(strchr(path_utf8, '\n') == nullptr);
|
||||||
@ -60,17 +59,11 @@ Song::LoadFile(Storage &storage, const char *path_utf8,
|
|||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Song::UpdateFile(Storage &storage) noexcept
|
Song::UpdateFile(Storage &storage)
|
||||||
{
|
{
|
||||||
const auto &relative_uri = GetURI();
|
const auto &relative_uri = GetURI();
|
||||||
|
|
||||||
StorageFileInfo info;
|
const auto info = storage.GetInfo(relative_uri.c_str(), true);
|
||||||
try {
|
|
||||||
info = storage.GetInfo(relative_uri.c_str(), true);
|
|
||||||
} catch (...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!info.IsRegular())
|
if (!info.IsRegular())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -105,13 +105,23 @@ struct Song {
|
|||||||
* allocate a new song structure with a local file name and attempt to
|
* allocate a new song structure with a local file name and attempt to
|
||||||
* load its metadata. If all decoder plugin fail to read its meta
|
* load its metadata. If all decoder plugin fail to read its meta
|
||||||
* data, nullptr is returned.
|
* data, nullptr is returned.
|
||||||
|
*
|
||||||
|
* Throws on error.
|
||||||
|
*
|
||||||
|
* @return the song on success, nullptr if the file was not
|
||||||
|
* recognized
|
||||||
*/
|
*/
|
||||||
static SongPtr LoadFile(Storage &storage, const char *name_utf8,
|
static SongPtr LoadFile(Storage &storage, const char *name_utf8,
|
||||||
Directory &parent) noexcept;
|
Directory &parent);
|
||||||
|
|
||||||
void Free() noexcept;
|
void Free() noexcept;
|
||||||
|
|
||||||
bool UpdateFile(Storage &storage) noexcept;
|
/**
|
||||||
|
* Throws on error.
|
||||||
|
*
|
||||||
|
* @return true on success, false if the file was not recognized
|
||||||
|
*/
|
||||||
|
bool UpdateFile(Storage &storage);
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
static SongPtr LoadFromArchive(ArchiveFile &archive,
|
static SongPtr LoadFromArchive(ArchiveFile &archive,
|
||||||
|
@ -33,7 +33,7 @@ inline void
|
|||||||
UpdateWalk::UpdateSongFile2(Directory &directory,
|
UpdateWalk::UpdateSongFile2(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const StorageFileInfo &info) noexcept
|
const StorageFileInfo &info) noexcept
|
||||||
{
|
try {
|
||||||
Song *song;
|
Song *song;
|
||||||
{
|
{
|
||||||
const ScopeDatabaseLock protect;
|
const ScopeDatabaseLock protect;
|
||||||
@ -61,6 +61,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
|
|||||||
if (song == nullptr) {
|
if (song == nullptr) {
|
||||||
FormatDebug(update_domain, "reading %s/%s",
|
FormatDebug(update_domain, "reading %s/%s",
|
||||||
directory.GetPath(), name);
|
directory.GetPath(), name);
|
||||||
|
|
||||||
auto new_song = Song::LoadFile(storage, name, directory);
|
auto new_song = Song::LoadFile(storage, name, directory);
|
||||||
if (!new_song) {
|
if (!new_song) {
|
||||||
FormatDebug(update_domain,
|
FormatDebug(update_domain,
|
||||||
@ -89,6 +90,10 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
|
|||||||
|
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
FormatError(std::current_exception(),
|
||||||
|
"error reading file %s/%s",
|
||||||
|
directory.GetPath(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Loading…
Reference in New Issue
Block a user