diff options
author | Max Kellermann <max@musicpd.org> | 2016-10-27 08:40:40 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2016-10-27 21:35:19 +0200 |
commit | c598686bd90aa49285e3e6bb7ad222231e1d3995 (patch) | |
tree | 990dfb1d047ee28b9a6754fafa09354892928228 /src/command/StorageCommands.cxx | |
parent | cab87e9398bcaf9dd5a8cfbfcf2cca4ee8e581ae (diff) |
storage: migrate from class Error to C++ exceptions
Diffstat (limited to 'src/command/StorageCommands.cxx')
-rw-r--r-- | src/command/StorageCommands.cxx | 49 |
1 files changed, 12 insertions, 37 deletions
diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx index bbb22d132..48e1033fa 100644 --- a/src/command/StorageCommands.cxx +++ b/src/command/StorageCommands.cxx @@ -58,9 +58,8 @@ skip_path(const char *name_utf8) #pragma GCC diagnostic ignored "-Wformat-extra-args" #endif -static bool -handle_listfiles_storage(Response &r, StorageDirectoryReader &reader, - Error &error) +static void +handle_listfiles_storage(Response &r, StorageDirectoryReader &reader) { const char *name_utf8; while ((name_utf8 = reader.Read()) != nullptr) { @@ -68,8 +67,11 @@ handle_listfiles_storage(Response &r, StorageDirectoryReader &reader, continue; StorageFileInfo info; - if (!reader.GetInfo(false, info, error)) + try { + info = reader.GetInfo(false); + } catch (const std::runtime_error &) { continue; + } switch (info.type) { case StorageFileInfo::Type::OTHER: @@ -91,53 +93,30 @@ handle_listfiles_storage(Response &r, StorageDirectoryReader &reader, if (info.mtime != 0) time_print(r, "Last-Modified", info.mtime); } - - return true; } #if defined(WIN32) && GCC_CHECK_VERSION(4,6) #pragma GCC diagnostic pop #endif -static bool -handle_listfiles_storage(Response &r, Storage &storage, const char *uri, - Error &error) -{ - std::unique_ptr<StorageDirectoryReader> reader(storage.OpenDirectory(uri, error)); - if (reader == nullptr) - return false; - - return handle_listfiles_storage(r, *reader, error); -} - CommandResult handle_listfiles_storage(Response &r, Storage &storage, const char *uri) { - Error error; - if (!handle_listfiles_storage(r, storage, uri, error)) - return print_error(r, error); - + std::unique_ptr<StorageDirectoryReader> reader(storage.OpenDirectory(uri)); + handle_listfiles_storage(r, *reader); return CommandResult::OK; } CommandResult handle_listfiles_storage(Response &r, const char *uri) { - Error error; - std::unique_ptr<Storage> storage(CreateStorageURI(io_thread_get(), uri, - error)); + std::unique_ptr<Storage> storage(CreateStorageURI(io_thread_get(), uri)); if (storage == nullptr) { - if (error.IsDefined()) - return print_error(r, error); - r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); return CommandResult::ERROR; } - if (!handle_listfiles_storage(r, *storage, "", error)) - return print_error(r, error); - - return CommandResult::OK; + return handle_listfiles_storage(r, *storage, ""); } static void @@ -217,13 +196,8 @@ handle_mount(Client &client, Request args, Response &r) return CommandResult::ERROR; } - Error error; - Storage *storage = CreateStorageURI(io_thread_get(), remote_uri, - error); + Storage *storage = CreateStorageURI(io_thread_get(), remote_uri); if (storage == nullptr) { - if (error.IsDefined()) - return print_error(r, error); - r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); return CommandResult::ERROR; } @@ -237,6 +211,7 @@ handle_mount(Client &client, Request args, Response &r) SimpleDatabase &db = *(SimpleDatabase *)_db; try { + Error error; if (!db.Mount(local_uri, remote_uri, error)) { composite.Unmount(local_uri); return print_error(r, error); |