Commit b8259e60 authored by Max Kellermann's avatar Max Kellermann

db/update/{Walk,ExcludeList}: use InputStream to read .mpdignore

Supports .mpdignore on NFS/SMB and others (closes #290).
parent 86e2075c
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#include "ExcludeList.hxx" #include "ExcludeList.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/NarrowPath.hxx" #include "fs/NarrowPath.hxx"
#include "fs/io/TextFile.hxx" #include "input/TextInputStream.hxx"
#include "system/Error.hxx" #include "util/StringUtil.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <stdexcept> #include <stdexcept>
...@@ -44,13 +44,13 @@ ExcludeList::ParseLine(char *line) noexcept ...@@ -44,13 +44,13 @@ ExcludeList::ParseLine(char *line) noexcept
} }
bool bool
ExcludeList::LoadFile(Path path_fs) noexcept ExcludeList::Load(InputStreamPtr is)
try { {
#ifdef HAVE_CLASS_GLOB #ifdef HAVE_CLASS_GLOB
TextFile file(path_fs); TextInputStream tis(std::move(is));
char *line; char *line;
while ((line = file.ReadLine()) != nullptr) while ((line = tis.ReadLine()) != nullptr)
ParseLine(line); ParseLine(line);
#else #else
/* not implemented */ /* not implemented */
...@@ -58,13 +58,6 @@ try { ...@@ -58,13 +58,6 @@ try {
#endif #endif
return true; 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 bool
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "check.h" #include "check.h"
#include "Compiler.h" #include "Compiler.h"
#include "fs/Glob.hxx" #include "fs/Glob.hxx"
#include "input/Ptr.hxx"
#ifdef HAVE_CLASS_GLOB #ifdef HAVE_CLASS_GLOB
#include <forward_list> #include <forward_list>
...@@ -62,7 +63,7 @@ public: ...@@ -62,7 +63,7 @@ public:
/** /**
* Loads and parses a .mpdignore file. * Loads and parses a .mpdignore file.
*/ */
bool LoadFile(Path path_fs) noexcept; bool Load(InputStreamPtr is);
/** /**
* Checks whether one of the patterns in the .mpdignore file matches * Checks whether one of the patterns in the .mpdignore file matches
......
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "storage/FileInfo.hxx" #include "storage/FileInfo.hxx"
#include "input/InputStream.hxx"
#include "input/Error.hxx"
#include "thread/Cond.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
...@@ -345,11 +348,16 @@ UpdateWalk::UpdateDirectory(Directory &directory, ...@@ -345,11 +348,16 @@ UpdateWalk::UpdateDirectory(Directory &directory,
ExcludeList child_exclude_list(exclude_list); ExcludeList child_exclude_list(exclude_list);
{ try {
const auto exclude_path_fs = Mutex mutex;
storage.MapChildFS(directory.GetPath(), ".mpdignore"); Cond cond;
if (!exclude_path_fs.IsNull()) auto is = InputStream::OpenReady(PathTraitsUTF8::Build(storage.MapUTF8(directory.GetPath()).c_str(),
child_exclude_list.LoadFile(exclude_path_fs); ".mpdignore").c_str(),
mutex, cond);
child_exclude_list.Load(std::move(is));
} catch (...) {
if (!IsFileNotFound(std::current_exception()))
LogError(std::current_exception());
} }
if (!child_exclude_list.IsEmpty()) if (!child_exclude_list.IsEmpty())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment