fs/DirectoryReader: use C++ exceptions instead of class Error

This commit is contained in:
Max Kellermann
2015-12-29 12:41:45 +01:00
parent 826a654c95
commit f3503e0026
12 changed files with 79 additions and 76 deletions

View File

@@ -70,15 +70,9 @@ skip_path(Path name_fs)
#endif
CommandResult
handle_listfiles_local(Response &r,
const char *path_utf8, Path path_fs)
handle_listfiles_local(Response &r, Path path_fs)
{
DirectoryReader reader(path_fs);
if (reader.HasFailed()) {
Error error;
error.FormatErrno("Failed to open '%s'", path_utf8);
return print_error(r, error);
}
while (reader.ReadEntry()) {
const Path name_fs = reader.GetEntry();

View File

@@ -28,8 +28,7 @@ class Response;
class Path;
CommandResult
handle_listfiles_local(Response &response,
const char *path_utf8, Path path_fs);
handle_listfiles_local(Response &response, Path path_fs);
CommandResult
handle_read_comments(Client &client, Request request, Response &response);

View File

@@ -49,6 +49,7 @@
#include "Partition.hxx"
#include "Instance.hxx"
#include "Idle.hxx"
#include "Log.hxx"
#ifdef ENABLE_DATABASE
#include "DatabaseCommands.hxx"
@@ -161,8 +162,7 @@ handle_listfiles(Client &client, Request args, Response &r)
case LocatedUri::Type::PATH:
/* list local directory */
return handle_listfiles_local(r, located_uri.canonical_uri,
located_uri.path);
return handle_listfiles_local(r, located_uri.path);
}
gcc_unreachable();
@@ -197,9 +197,11 @@ handle_lsinfo_relative(Client &client, Response &r, const char *uri)
#endif
if (isRootDirectory(uri)) {
Error error;
const auto &list = ListPlaylistFiles(error);
print_spl_list(r, list);
try {
print_spl_list(r, ListPlaylistFiles());
} catch (const std::exception &e) {
LogError(e);
}
} else {
#ifndef ENABLE_DATABASE
r.Error(ACK_ERROR_NO_EXIST, "No database");

View File

@@ -198,11 +198,6 @@ CommandResult
handle_listplaylists(gcc_unused Client &client, gcc_unused Request args,
Response &r)
{
Error error;
const auto list = ListPlaylistFiles(error);
if (list.empty() && error.IsDefined())
return print_error(r, error);
print_spl_list(r, list);
print_spl_list(r, ListPlaylistFiles());
return CommandResult::OK;
}