fs/io/Reader: use C++ exceptions instead of class Error

This commit is contained in:
Max Kellermann
2015-12-16 11:05:33 +01:00
parent fe60c52c70
commit e6e7d6dbd6
33 changed files with 192 additions and 334 deletions

View File

@@ -27,41 +27,18 @@
#include "fs/Path.hxx"
#include "fs/NarrowPath.hxx"
#include "fs/io/TextFile.hxx"
#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "system/Error.hxx"
#include "Log.hxx"
#include <assert.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_CLASS_GLOB
gcc_pure
static bool
IsFileNotFound(const Error &error)
{
#ifdef WIN32
return error.IsDomain(win32_domain) &&
error.GetCode() == ERROR_FILE_NOT_FOUND;
#else
return error.IsDomain(errno_domain) && error.GetCode() == ENOENT;
#endif
}
#endif
bool
ExcludeList::LoadFile(Path path_fs)
{
try {
#ifdef HAVE_CLASS_GLOB
Error error;
TextFile file(path_fs, error);
if (file.HasFailed()) {
if (!IsFileNotFound(error))
LogError(error);
return false;
}
TextFile file(path_fs);
char *line;
while ((line = file.ReadLine()) != nullptr) {
@@ -79,6 +56,13 @@ ExcludeList::LoadFile(Path path_fs)
#endif
return true;
} catch (const std::system_error &e) {
if (!IsFileNotFound(e))
LogError(e);
return false;
} catch (const std::exception &e) {
LogError(e);
return false;
}
bool