diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index f8686f161..78741dc3e 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -35,6 +35,8 @@ #include "TagArchive.hxx" #endif +#include + #include #include @@ -65,8 +67,13 @@ Song::UpdateFile(Storage &storage) const auto &relative_uri = GetURI(); StorageFileInfo info; - if (!storage.GetInfo(relative_uri.c_str(), true, info, IgnoreError())) + try { + if (!storage.GetInfo(relative_uri.c_str(), true, info, + IgnoreError())) + return false; + } catch (const std::runtime_error &) { return false; + } if (!info.IsRegular()) return false; diff --git a/src/db/update/UpdateIO.cxx b/src/db/update/UpdateIO.cxx index 7bf743ce8..da6e4a096 100644 --- a/src/db/update/UpdateIO.cxx +++ b/src/db/update/UpdateIO.cxx @@ -28,34 +28,47 @@ #include "util/Error.hxx" #include "Log.hxx" +#include + #include bool GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) -{ +try { Error error; bool success = storage.GetInfo(uri_utf8, true, info, error); if (!success) LogError(error); return success; +} catch (const std::runtime_error &e) { + LogError(e); + return false; } bool GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) -{ +try { Error error; bool success = reader.GetInfo(true, info, error); if (!success) LogError(error); return success; +} catch (const std::runtime_error &e) { + LogError(e); + return false; } bool DirectoryExists(Storage &storage, const Directory &directory) { StorageFileInfo info; - if (!storage.GetInfo(directory.GetPath(), true, info, IgnoreError())) + + try { + if (!storage.GetInfo(directory.GetPath(), true, info, IgnoreError())) + return false; + } catch (const std::runtime_error &) { return false; + } return directory.device == DEVICE_INARCHIVE || directory.device == DEVICE_CONTAINER @@ -75,11 +88,13 @@ GetDirectoryChildInfo(Storage &storage, const Directory &directory, bool directory_child_is_regular(Storage &storage, const Directory &directory, const char *name_utf8) -{ +try { StorageFileInfo info; return GetDirectoryChildInfo(storage, directory, name_utf8, info, IgnoreError()) && info.IsRegular(); + } catch (const std::runtime_error &) { + return false; } bool diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index ecbf02503..f9a697fdc 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -42,11 +42,13 @@ #include "util/Error.hxx" #include "Log.hxx" +#include +#include + #include #include #include #include -#include UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener, Storage &_storage) @@ -333,10 +335,17 @@ UpdateWalk::UpdateDirectory(Directory &directory, directory_set_stat(directory, info); - Error error; - const std::unique_ptr reader(storage.OpenDirectory(directory.GetPath(), error)); - if (reader.get() == nullptr) { - LogError(error); + std::unique_ptr reader; + + try { + Error error; + reader.reset(storage.OpenDirectory(directory.GetPath(), error)); + if (!reader) { + LogError(error); + return false; + } + } catch (const std::runtime_error &e) { + LogError(e); return false; }