db/ExcludeList: use the TextFile class instead of stdio.h
This commit is contained in:
@@ -25,36 +25,45 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ExcludeList.hxx"
|
#include "ExcludeList.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/FileSystem.hxx"
|
#include "fs/io/TextFile.hxx"
|
||||||
#include "util/StringUtil.hxx"
|
#include "util/StringUtil.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static constexpr Domain exclude_list_domain("exclude_list");
|
#ifdef HAVE_GLIB
|
||||||
|
|
||||||
|
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
|
bool
|
||||||
ExcludeList::LoadFile(Path path_fs)
|
ExcludeList::LoadFile(Path path_fs)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GLIB
|
#ifdef HAVE_GLIB
|
||||||
FILE *file = FOpen(path_fs, FOpenMode::ReadText);
|
Error error;
|
||||||
if (file == nullptr) {
|
TextFile file(path_fs, error);
|
||||||
const int e = errno;
|
if (file.HasFailed()) {
|
||||||
if (e != ENOENT) {
|
if (!IsFileNotFound(error))
|
||||||
const auto path_utf8 = path_fs.ToUTF8();
|
LogError(error);
|
||||||
FormatErrno(exclude_list_domain,
|
|
||||||
"Failed to open %s",
|
|
||||||
path_utf8.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[1024];
|
char *line;
|
||||||
while (fgets(line, sizeof(line), file) != nullptr) {
|
while ((line = file.ReadLine()) != nullptr) {
|
||||||
char *p = strchr(line, '#');
|
char *p = strchr(line, '#');
|
||||||
if (p != nullptr)
|
if (p != nullptr)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
@@ -63,8 +72,6 @@ ExcludeList::LoadFile(Path path_fs)
|
|||||||
if (*p != 0)
|
if (*p != 0)
|
||||||
patterns.emplace_front(p);
|
patterns.emplace_front(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
#else
|
#else
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
(void)path_fs;
|
(void)path_fs;
|
||||||
|
Reference in New Issue
Block a user