update: apply .mpdignore matches to subdirectories
Wildcard matches are directly applied to all filenames in subdirectories without any attempt at matching relative paths. This change is based on the following feature request: http://bugs.musicpd.org/view.php?id=3729
This commit is contained in:
parent
de332a16d1
commit
6b6c7b0920
2
NEWS
2
NEWS
|
@ -36,6 +36,8 @@ ver 0.20 (not yet released)
|
||||||
* support libsystemd (instead of the older libsystemd-daemon)
|
* support libsystemd (instead of the older libsystemd-daemon)
|
||||||
* database
|
* database
|
||||||
- proxy: add TCP keepalive option
|
- proxy: add TCP keepalive option
|
||||||
|
* update
|
||||||
|
- apply .mpdignore matches to subdirectories
|
||||||
|
|
||||||
ver 0.19.10 (2015/06/21)
|
ver 0.19.10 (2015/06/21)
|
||||||
* input
|
* input
|
||||||
|
|
|
@ -1077,6 +1077,8 @@ database {
|
||||||
To exclude a file from the update, create a file called
|
To exclude a file from the update, create a file called
|
||||||
<filename>.mpdignore</filename> in its parent directory. Each
|
<filename>.mpdignore</filename> in its parent directory. Each
|
||||||
line of that file may contain a list of shell wildcards.
|
line of that file may contain a list of shell wildcards.
|
||||||
|
Matching files in the current directory and all subdirectories
|
||||||
|
are excluded.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,12 @@ ExcludeList::Check(Path name_fs) const
|
||||||
/* XXX include full path name in check */
|
/* XXX include full path name in check */
|
||||||
|
|
||||||
#ifdef HAVE_CLASS_GLOB
|
#ifdef HAVE_CLASS_GLOB
|
||||||
|
if (parent != nullptr) {
|
||||||
|
if (parent->Check(name_fs)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &i : patterns)
|
for (const auto &i : patterns)
|
||||||
if (i.Check(NarrowPath(name_fs).c_str()))
|
if (i.Check(NarrowPath(name_fs).c_str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -36,15 +36,23 @@
|
||||||
class Path;
|
class Path;
|
||||||
|
|
||||||
class ExcludeList {
|
class ExcludeList {
|
||||||
|
const ExcludeList *const parent;
|
||||||
|
|
||||||
#ifdef HAVE_CLASS_GLOB
|
#ifdef HAVE_CLASS_GLOB
|
||||||
std::forward_list<Glob> patterns;
|
std::forward_list<Glob> patterns;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ExcludeList()
|
||||||
|
:parent(nullptr) {}
|
||||||
|
|
||||||
|
ExcludeList(const ExcludeList &_parent)
|
||||||
|
:parent(&_parent) {}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool IsEmpty() const {
|
bool IsEmpty() const {
|
||||||
#ifdef HAVE_CLASS_GLOB
|
#ifdef HAVE_CLASS_GLOB
|
||||||
return patterns.empty();
|
return ((parent == nullptr) || parent->IsEmpty()) && patterns.empty();
|
||||||
#else
|
#else
|
||||||
/* not implemented */
|
/* not implemented */
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -219,6 +219,7 @@ UpdateWalk::UpdateRegularFile(Directory &directory,
|
||||||
|
|
||||||
void
|
void
|
||||||
UpdateWalk::UpdateDirectoryChild(Directory &directory,
|
UpdateWalk::UpdateDirectoryChild(Directory &directory,
|
||||||
|
const ExcludeList &exclude_list,
|
||||||
const char *name, const StorageFileInfo &info)
|
const char *name, const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
assert(strchr(name, '/') == nullptr);
|
assert(strchr(name, '/') == nullptr);
|
||||||
|
@ -236,7 +237,7 @@ UpdateWalk::UpdateDirectoryChild(Directory &directory,
|
||||||
|
|
||||||
assert(&directory == subdir->parent);
|
assert(&directory == subdir->parent);
|
||||||
|
|
||||||
if (!UpdateDirectory(*subdir, info))
|
if (!UpdateDirectory(*subdir, exclude_list, info))
|
||||||
editor.LockDeleteDirectory(subdir);
|
editor.LockDeleteDirectory(subdir);
|
||||||
} else {
|
} else {
|
||||||
FormatDebug(update_domain,
|
FormatDebug(update_domain,
|
||||||
|
@ -327,7 +328,9 @@ UpdateWalk::SkipSymlink(const Directory *directory,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateDirectory(Directory &directory, const StorageFileInfo &info)
|
UpdateWalk::UpdateDirectory(Directory &directory,
|
||||||
|
const ExcludeList &exclude_list,
|
||||||
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
assert(info.IsDirectory());
|
assert(info.IsDirectory());
|
||||||
|
|
||||||
|
@ -340,17 +343,17 @@ UpdateWalk::UpdateDirectory(Directory &directory, const StorageFileInfo &info)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcludeList exclude_list;
|
ExcludeList child_exclude_list(exclude_list);
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto exclude_path_fs =
|
const auto exclude_path_fs =
|
||||||
storage.MapChildFS(directory.GetPath(), ".mpdignore");
|
storage.MapChildFS(directory.GetPath(), ".mpdignore");
|
||||||
if (!exclude_path_fs.IsNull())
|
if (!exclude_path_fs.IsNull())
|
||||||
exclude_list.LoadFile(exclude_path_fs);
|
child_exclude_list.LoadFile(exclude_path_fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exclude_list.IsEmpty())
|
if (!child_exclude_list.IsEmpty())
|
||||||
RemoveExcludedFromDirectory(directory, exclude_list);
|
RemoveExcludedFromDirectory(directory, child_exclude_list);
|
||||||
|
|
||||||
PurgeDeletedFromDirectory(directory);
|
PurgeDeletedFromDirectory(directory);
|
||||||
|
|
||||||
|
@ -361,7 +364,7 @@ UpdateWalk::UpdateDirectory(Directory &directory, const StorageFileInfo &info)
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto name_fs = AllocatedPath::FromUTF8(name_utf8);
|
const auto name_fs = AllocatedPath::FromUTF8(name_utf8);
|
||||||
if (name_fs.IsNull() || exclude_list.Check(name_fs))
|
if (name_fs.IsNull() || child_exclude_list.Check(name_fs))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +379,7 @@ UpdateWalk::UpdateDirectory(Directory &directory, const StorageFileInfo &info)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateDirectoryChild(directory, name_utf8, info2);
|
UpdateDirectoryChild(directory, child_exclude_list, name_utf8, info2);
|
||||||
}
|
}
|
||||||
|
|
||||||
directory.mtime = info.mtime;
|
directory.mtime = info.mtime;
|
||||||
|
@ -468,7 +471,9 @@ UpdateWalk::UpdateUri(Directory &root, const char *uri)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateDirectoryChild(*parent, name, info);
|
ExcludeList exclude_list;
|
||||||
|
|
||||||
|
UpdateDirectoryChild(*parent, exclude_list, name, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -484,7 +489,9 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard)
|
||||||
if (!GetInfo(storage, "", info))
|
if (!GetInfo(storage, "", info))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
UpdateDirectory(root, info);
|
ExcludeList exclude_list;
|
||||||
|
|
||||||
|
UpdateDirectory(root, exclude_list, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return modified;
|
return modified;
|
||||||
|
|
|
@ -129,10 +129,12 @@ private:
|
||||||
const char *name, const StorageFileInfo &info);
|
const char *name, const StorageFileInfo &info);
|
||||||
|
|
||||||
void UpdateDirectoryChild(Directory &directory,
|
void UpdateDirectoryChild(Directory &directory,
|
||||||
|
const ExcludeList &exclude_list,
|
||||||
const char *name,
|
const char *name,
|
||||||
const StorageFileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
bool UpdateDirectory(Directory &directory,
|
bool UpdateDirectory(Directory &directory,
|
||||||
|
const ExcludeList &exclude_list,
|
||||||
const StorageFileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue