diff options
Diffstat (limited to 'src/db/update')
27 files changed, 159 insertions, 146 deletions
diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx index fc8f1fcbf..e818ab279 100644 --- a/src/db/update/Archive.cxx +++ b/src/db/update/Archive.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -104,7 +104,7 @@ class UpdateArchiveVisitor final : public ArchiveVisitor { */ void UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name, - const FileInfo &info, + const StorageFileInfo &info, const ArchivePlugin &plugin) { db_lock(); @@ -156,7 +156,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name, bool UpdateWalk::UpdateArchiveFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info) + const StorageFileInfo &info) { const ArchivePlugin *plugin = archive_plugin_from_suffix(suffix); if (plugin == nullptr) diff --git a/src/db/update/Container.cxx b/src/db/update/Container.cxx index 1c420fa99..93ba5ff20 100644 --- a/src/db/update/Container.cxx +++ b/src/db/update/Container.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -36,7 +36,7 @@ Directory * UpdateWalk::MakeDirectoryIfModified(Directory &parent, const char *name, - const FileInfo &info) + const StorageFileInfo &info) { Directory *directory = parent.FindChild(name); @@ -69,7 +69,7 @@ SupportsContainerSuffix(const DecoderPlugin &plugin, const char *suffix) bool UpdateWalk::UpdateContainerFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info) + const StorageFileInfo &info) { const DecoderPlugin *_plugin = decoder_plugins_find([suffix](const DecoderPlugin &plugin){ return SupportsContainerSuffix(plugin, suffix); @@ -106,8 +106,11 @@ UpdateWalk::UpdateContainerFile(Directory &directory, // shouldn't be necessary but it's there.. song->mtime = info.mtime; + const auto vtrack_fs = AllocatedPath::FromUTF8(vtrack); + // TODO: check vtrack_fs.IsNull() + const auto child_path_fs = AllocatedPath::Build(pathname, - vtrack); + vtrack_fs); plugin.ScanFile(child_path_fs, add_tag_handler, &tag_builder); diff --git a/src/db/update/Editor.cxx b/src/db/update/Editor.cxx index 4136ccdad..2ca17f8cb 100644 --- a/src/db/update/Editor.cxx +++ b/src/db/update/Editor.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Editor.hxx b/src/db/update/Editor.hxx index 58e23ed7a..cefb6c07f 100644 --- a/src/db/update/Editor.hxx +++ b/src/db/update/Editor.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/ExcludeList.cxx b/src/db/update/ExcludeList.cxx index cf92ac8f7..b09f349ac 100644 --- a/src/db/update/ExcludeList.cxx +++ b/src/db/update/ExcludeList.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -25,36 +25,46 @@ #include "config.h" #include "ExcludeList.hxx" #include "fs/Path.hxx" -#include "fs/FileSystem.hxx" +#include "fs/NarrowPath.hxx" +#include "fs/io/TextFile.hxx" #include "util/StringUtil.hxx" -#include "util/Domain.hxx" +#include "util/Error.hxx" #include "Log.hxx" #include <assert.h> #include <string.h> #include <errno.h> -static constexpr Domain exclude_list_domain("exclude_list"); +#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) { -#ifdef HAVE_GLIB - FILE *file = FOpen(path_fs, FOpenMode::ReadText); - if (file == nullptr) { - const int e = errno; - if (e != ENOENT) { - const auto path_utf8 = path_fs.ToUTF8(); - FormatErrno(exclude_list_domain, - "Failed to open %s", - path_utf8.c_str()); - } - +#ifdef HAVE_CLASS_GLOB + Error error; + TextFile file(path_fs, error); + if (file.HasFailed()) { + if (!IsFileNotFound(error)) + LogError(error); return false; } - char line[1024]; - while (fgets(line, sizeof(line), file) != nullptr) { + char *line; + while ((line = file.ReadLine()) != nullptr) { char *p = strchr(line, '#'); if (p != nullptr) *p = 0; @@ -63,10 +73,8 @@ ExcludeList::LoadFile(Path path_fs) if (*p != 0) patterns.emplace_front(p); } - - fclose(file); #else - // TODO: implement + /* not implemented */ (void)path_fs; #endif @@ -80,12 +88,18 @@ ExcludeList::Check(Path name_fs) const /* XXX include full path name in check */ -#ifdef HAVE_GLIB +#ifdef HAVE_CLASS_GLOB + if (parent != nullptr) { + if (parent->Check(name_fs)) { + return true; + } + } + for (const auto &i : patterns) - if (i.Check(name_fs.c_str())) + if (i.Check(NarrowPath(name_fs).c_str())) return true; #else - // TODO: implement + /* not implemented */ (void)name_fs; #endif diff --git a/src/db/update/ExcludeList.hxx b/src/db/update/ExcludeList.hxx index ef6c4d53e..4952d291a 100644 --- a/src/db/update/ExcludeList.hxx +++ b/src/db/update/ExcludeList.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -27,51 +27,34 @@ #include "check.h" #include "Compiler.h" +#include "fs/Glob.hxx" +#ifdef HAVE_CLASS_GLOB #include <forward_list> - -#ifdef HAVE_GLIB -#include <glib.h> #endif class Path; class ExcludeList { -#ifdef HAVE_GLIB - class Pattern { - GPatternSpec *pattern; - - public: - Pattern(const char *_pattern) - :pattern(g_pattern_spec_new(_pattern)) {} - - Pattern(Pattern &&other) - :pattern(other.pattern) { - other.pattern = nullptr; - } - - ~Pattern() { - g_pattern_spec_free(pattern); - } + const ExcludeList *const parent; - gcc_pure - bool Check(const char *name_fs) const { - return g_pattern_match_string(pattern, name_fs); - } - }; - - std::forward_list<Pattern> patterns; -#else - // TODO: implement +#ifdef HAVE_CLASS_GLOB + std::forward_list<Glob> patterns; #endif public: + ExcludeList() + :parent(nullptr) {} + + ExcludeList(const ExcludeList &_parent) + :parent(&_parent) {} + gcc_pure bool IsEmpty() const { -#ifdef HAVE_GLIB - return patterns.empty(); +#ifdef HAVE_CLASS_GLOB + return ((parent == nullptr) || parent->IsEmpty()) && patterns.empty(); #else - // TODO: implement + /* not implemented */ return true; #endif } diff --git a/src/db/update/InotifyDomain.cxx b/src/db/update/InotifyDomain.cxx index 4a3ab2d79..18557a5ce 100644 --- a/src/db/update/InotifyDomain.cxx +++ b/src/db/update/InotifyDomain.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/InotifyDomain.hxx b/src/db/update/InotifyDomain.hxx index ad6202361..219ee7e4f 100644 --- a/src/db/update/InotifyDomain.hxx +++ b/src/db/update/InotifyDomain.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/InotifyQueue.cxx b/src/db/update/InotifyQueue.cxx index 013200f98..4b5269427 100644 --- a/src/db/update/InotifyQueue.cxx +++ b/src/db/update/InotifyQueue.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/InotifyQueue.hxx b/src/db/update/InotifyQueue.hxx index a9abc2969..dab7c7e8c 100644 --- a/src/db/update/InotifyQueue.hxx +++ b/src/db/update/InotifyQueue.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/InotifySource.cxx b/src/db/update/InotifySource.cxx index 233504ad6..b084dd60a 100644 --- a/src/db/update/InotifySource.cxx +++ b/src/db/update/InotifySource.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -21,7 +21,7 @@ #include "InotifySource.hxx" #include "InotifyDomain.hxx" #include "util/Error.hxx" -#include "system/fd_util.h" +#include "system/FileDescriptor.hxx" #include "system/FatalError.hxx" #include "Log.hxx" @@ -72,8 +72,8 @@ InotifySource::OnSocketReady(gcc_unused unsigned flags) inline InotifySource::InotifySource(EventLoop &_loop, mpd_inotify_callback_t _callback, void *_ctx, - int _fd) - :SocketMonitor(_fd, _loop), + FileDescriptor _fd) + :SocketMonitor(_fd.Get(), _loop), callback(_callback), callback_ctx(_ctx) { ScheduleRead(); @@ -85,8 +85,8 @@ InotifySource::Create(EventLoop &loop, mpd_inotify_callback_t callback, void *callback_ctx, Error &error) { - int fd = inotify_init_cloexec(); - if (fd < 0) { + FileDescriptor fd; + if (!fd.CreateInotify()) { error.SetErrno("inotify_init() has failed"); return nullptr; } diff --git a/src/db/update/InotifySource.hxx b/src/db/update/InotifySource.hxx index 2557680a0..34d84c2dd 100644 --- a/src/db/update/InotifySource.hxx +++ b/src/db/update/InotifySource.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "Compiler.h" class Error; +class FileDescriptor; typedef void (*mpd_inotify_callback_t)(int wd, unsigned mask, const char *name, void *ctx); @@ -33,7 +34,8 @@ class InotifySource final : private SocketMonitor { void *callback_ctx; InotifySource(EventLoop &_loop, - mpd_inotify_callback_t callback, void *ctx, int fd); + mpd_inotify_callback_t callback, void *ctx, + FileDescriptor fd); public: ~InotifySource() { @@ -41,10 +43,11 @@ public: } /** - * Creates a new inotify source and registers it in the GLib main - * loop. + * Creates a new inotify source and registers it in the + * #EventLoop. * - * @param a callback invoked for events received from the kernel + * @param callback a callback invoked for events received from + * the kernel */ static InotifySource *Create(EventLoop &_loop, mpd_inotify_callback_t callback, diff --git a/src/db/update/InotifyUpdate.cxx b/src/db/update/InotifyUpdate.cxx index 26bdddf8d..f699b7f78 100644 --- a/src/db/update/InotifyUpdate.cxx +++ b/src/db/update/InotifyUpdate.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #include "InotifyDomain.hxx" #include "storage/StorageInterface.hxx" #include "fs/AllocatedPath.hxx" -#include "fs/FileSystem.hxx" +#include "fs/FileInfo.hxx" #include "util/Error.hxx" #include "Log.hxx" @@ -179,7 +179,6 @@ recursive_watch_subdirectories(WatchDirectory *directory, } while ((ent = readdir(dir))) { - struct stat st; int ret; if (skip_path(ent->d_name)) @@ -187,15 +186,15 @@ recursive_watch_subdirectories(WatchDirectory *directory, const auto child_path_fs = AllocatedPath::Build(path_fs, ent->d_name); - ret = StatFile(child_path_fs, st); - if (ret < 0) { - FormatErrno(inotify_domain, - "Failed to stat %s", - child_path_fs.c_str()); + + FileInfo fi; + if (!GetFileInfo(child_path_fs, fi, error)) { + LogError(error); + error.Clear(); continue; } - if (!S_ISDIR(st.st_mode)) + if (!fi.IsDirectory()) continue; ret = inotify_source->Add(child_path_fs.c_str(), IN_MASK, diff --git a/src/db/update/InotifyUpdate.hxx b/src/db/update/InotifyUpdate.hxx index 0f78db71f..82b6cdf04 100644 --- a/src/db/update/InotifyUpdate.hxx +++ b/src/db/update/InotifyUpdate.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -32,6 +32,6 @@ mpd_inotify_init(EventLoop &loop, Storage &storage, UpdateService &update, unsigned max_depth); void -mpd_inotify_finish(void); +mpd_inotify_finish(); #endif diff --git a/src/db/update/Queue.cxx b/src/db/update/Queue.cxx index 6d6d80131..870207fc6 100644 --- a/src/db/update/Queue.cxx +++ b/src/db/update/Queue.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Queue.hxx b/src/db/update/Queue.hxx index 9064ea481..6c0a5733d 100644 --- a/src/db/update/Queue.hxx +++ b/src/db/update/Queue.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Remove.cxx b/src/db/update/Remove.cxx index dfada05b2..0f1cbde1c 100644 --- a/src/db/update/Remove.cxx +++ b/src/db/update/Remove.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Remove.hxx b/src/db/update/Remove.hxx index ce6d77d47..5ebfb884b 100644 --- a/src/db/update/Remove.hxx +++ b/src/db/update/Remove.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Service.cxx b/src/db/update/Service.cxx index e8a1f6b02..e14dbdc6c 100644 --- a/src/db/update/Service.cxx +++ b/src/db/update/Service.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/Service.hxx b/src/db/update/Service.hxx index feaeaebc5..7dd198a7f 100644 --- a/src/db/update/Service.hxx +++ b/src/db/update/Service.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/UpdateDomain.cxx b/src/db/update/UpdateDomain.cxx index 80ad4fd22..68fcbe81c 100644 --- a/src/db/update/UpdateDomain.cxx +++ b/src/db/update/UpdateDomain.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/UpdateDomain.hxx b/src/db/update/UpdateDomain.hxx index a6e994390..8669d24b4 100644 --- a/src/db/update/UpdateDomain.hxx +++ b/src/db/update/UpdateDomain.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/db/update/UpdateIO.cxx b/src/db/update/UpdateIO.cxx index 9e43d1289..1a0f318c3 100644 --- a/src/db/update/UpdateIO.cxx +++ b/src/db/update/UpdateIO.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -33,7 +33,7 @@ #include <unistd.h> bool -GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info) +GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info) { Error error; bool success = storage.GetInfo(uri_utf8, true, info, error); @@ -43,7 +43,7 @@ GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info) } bool -GetInfo(StorageDirectoryReader &reader, FileInfo &info) +GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info) { Error error; bool success = reader.GetInfo(true, info, error); @@ -55,7 +55,7 @@ GetInfo(StorageDirectoryReader &reader, FileInfo &info) bool DirectoryExists(Storage &storage, const Directory &directory) { - FileInfo info; + StorageFileInfo info; if (!storage.GetInfo(directory.GetPath(), true, info, IgnoreError())) return false; @@ -67,7 +67,7 @@ DirectoryExists(Storage &storage, const Directory &directory) static bool GetDirectoryChildInfo(Storage &storage, const Directory &directory, - const char *name_utf8, FileInfo &info, Error &error) + const char *name_utf8, StorageFileInfo &info, Error &error) { const auto uri_utf8 = PathTraitsUTF8::Build(directory.GetPath(), name_utf8); @@ -78,7 +78,7 @@ bool directory_child_is_regular(Storage &storage, const Directory &directory, const char *name_utf8) { - FileInfo info; + StorageFileInfo info; return GetDirectoryChildInfo(storage, directory, name_utf8, info, IgnoreError()) && info.IsRegular(); diff --git a/src/db/update/UpdateIO.hxx b/src/db/update/UpdateIO.hxx index 2dbb4ae83..0223cb62c 100644 --- a/src/db/update/UpdateIO.hxx +++ b/src/db/update/UpdateIO.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #include "Compiler.h" struct Directory; -struct FileInfo; +struct StorageFileInfo; class Storage; class StorageDirectoryReader; @@ -33,14 +33,14 @@ class StorageDirectoryReader; * returning them. */ bool -GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info); +GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info); /** * Wrapper for LocalDirectoryReader::GetInfo() that logs errors * instead of returning them. */ bool -GetInfo(StorageDirectoryReader &reader, FileInfo &info); +GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info); gcc_pure bool diff --git a/src/db/update/UpdateSong.cxx b/src/db/update/UpdateSong.cxx index 005bf8992..e6ed5643a 100644 --- a/src/db/update/UpdateSong.cxx +++ b/src/db/update/UpdateSong.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -33,7 +33,7 @@ inline void UpdateWalk::UpdateSongFile2(Directory &directory, const char *name, const char *suffix, - const FileInfo &info) + const StorageFileInfo &info) { db_lock(); Song *song = directory.FindSong(name); @@ -93,7 +93,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory, bool UpdateWalk::UpdateSongFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info) + const StorageFileInfo &info) { if (!decoder_plugins_supports_suffix(suffix)) return false; diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index 9fdb5bbdf..3e5654a3c 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -57,17 +57,17 @@ UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener, { #ifndef WIN32 follow_inside_symlinks = - config_get_bool(CONF_FOLLOW_INSIDE_SYMLINKS, + config_get_bool(ConfigOption::FOLLOW_INSIDE_SYMLINKS, DEFAULT_FOLLOW_INSIDE_SYMLINKS); follow_outside_symlinks = - config_get_bool(CONF_FOLLOW_OUTSIDE_SYMLINKS, + config_get_bool(ConfigOption::FOLLOW_OUTSIDE_SYMLINKS, DEFAULT_FOLLOW_OUTSIDE_SYMLINKS); #endif } static void -directory_set_stat(Directory &dir, const FileInfo &info) +directory_set_stat(Directory &dir, const StorageFileInfo &info) { dir.inode = info.inode; dir.device = info.device; @@ -140,7 +140,7 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) static bool update_directory_stat(Storage &storage, Directory &directory) { - FileInfo info; + StorageFileInfo info; if (!GetInfo(storage, directory.GetPath(), info)) return false; @@ -190,7 +190,7 @@ FindAncestorLoop(Storage &storage, Directory *parent, inline bool UpdateWalk::UpdatePlaylistFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info) + const StorageFileInfo &info) { if (!playlist_suffix_supported(suffix)) return false; @@ -206,7 +206,7 @@ UpdateWalk::UpdatePlaylistFile(Directory &directory, inline bool UpdateWalk::UpdateRegularFile(Directory &directory, - const char *name, const FileInfo &info) + const char *name, const StorageFileInfo &info) { const char *suffix = uri_get_suffix(name); if (suffix == nullptr) @@ -219,7 +219,8 @@ UpdateWalk::UpdateRegularFile(Directory &directory, void UpdateWalk::UpdateDirectoryChild(Directory &directory, - const char *name, const FileInfo &info) + const ExcludeList &exclude_list, + const char *name, const StorageFileInfo &info) { assert(strchr(name, '/') == nullptr); @@ -236,7 +237,7 @@ UpdateWalk::UpdateDirectoryChild(Directory &directory, assert(&directory == subdir->parent); - if (!UpdateDirectory(*subdir, info)) + if (!UpdateDirectory(*subdir, exclude_list, info)) editor.LockDeleteDirectory(subdir); } else { FormatDebug(update_domain, @@ -327,7 +328,9 @@ UpdateWalk::SkipSymlink(const Directory *directory, } bool -UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info) +UpdateWalk::UpdateDirectory(Directory &directory, + const ExcludeList &exclude_list, + const StorageFileInfo &info) { assert(info.IsDirectory()); @@ -340,17 +343,17 @@ UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info) return false; } - ExcludeList exclude_list; + ExcludeList child_exclude_list(exclude_list); { const auto exclude_path_fs = storage.MapChildFS(directory.GetPath(), ".mpdignore"); if (!exclude_path_fs.IsNull()) - exclude_list.LoadFile(exclude_path_fs); + child_exclude_list.LoadFile(exclude_path_fs); } - if (!exclude_list.IsEmpty()) - RemoveExcludedFromDirectory(directory, exclude_list); + if (!child_exclude_list.IsEmpty()) + RemoveExcludedFromDirectory(directory, child_exclude_list); PurgeDeletedFromDirectory(directory); @@ -361,7 +364,7 @@ UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info) { 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; } @@ -370,13 +373,13 @@ UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info) continue; } - FileInfo info2; + StorageFileInfo info2; if (!GetInfo(*reader, info2)) { modified |= editor.DeleteNameIn(directory, name_utf8); continue; } - UpdateDirectoryChild(directory, name_utf8, info2); + UpdateDirectoryChild(directory, child_exclude_list, name_utf8, info2); } directory.mtime = info.mtime; @@ -400,7 +403,7 @@ UpdateWalk::DirectoryMakeChildChecked(Directory &parent, return directory; } - FileInfo info; + StorageFileInfo info; if (!GetInfo(storage, uri_utf8, info) || FindAncestorLoop(storage, &parent, info.inode, info.device)) return nullptr; @@ -462,13 +465,15 @@ UpdateWalk::UpdateUri(Directory &root, const char *uri) return; } - FileInfo info; + StorageFileInfo info; if (!GetInfo(storage, uri, info)) { modified |= editor.DeleteNameIn(*parent, name); return; } - UpdateDirectoryChild(*parent, name, info); + ExcludeList exclude_list; + + UpdateDirectoryChild(*parent, exclude_list, name, info); } bool @@ -480,11 +485,13 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) if (path != nullptr && !isRootDirectory(path)) { UpdateUri(root, path); } else { - FileInfo info; + StorageFileInfo info; if (!GetInfo(storage, "", info)) return false; - UpdateDirectory(root, info); + ExcludeList exclude_list; + + UpdateDirectory(root, exclude_list, info); } return modified; diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx index a4c518813..99d54ef51 100644 --- a/src/db/update/Walk.hxx +++ b/src/db/update/Walk.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -27,7 +27,7 @@ #include <sys/stat.h> struct stat; -struct FileInfo; +struct StorageFileInfo; struct Directory; struct ArchivePlugin; class Storage; @@ -89,15 +89,15 @@ private: void UpdateSongFile2(Directory &directory, const char *name, const char *suffix, - const FileInfo &info); + const StorageFileInfo &info); bool UpdateSongFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info); + const StorageFileInfo &info); bool UpdateContainerFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info); + const StorageFileInfo &info); #ifdef ENABLE_ARCHIVE @@ -105,10 +105,10 @@ private: bool UpdateArchiveFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info); + const StorageFileInfo &info); void UpdateArchiveFile(Directory &directory, const char *name, - const FileInfo &info, + const StorageFileInfo &info, const ArchivePlugin &plugin); @@ -116,22 +116,26 @@ private: bool UpdateArchiveFile(gcc_unused Directory &directory, gcc_unused const char *name, gcc_unused const char *suffix, - gcc_unused const FileInfo &info) { + gcc_unused const StorageFileInfo &info) { return false; } #endif bool UpdatePlaylistFile(Directory &directory, const char *name, const char *suffix, - const FileInfo &info); + const StorageFileInfo &info); bool UpdateRegularFile(Directory &directory, - const char *name, const FileInfo &info); + const char *name, const StorageFileInfo &info); void UpdateDirectoryChild(Directory &directory, - const char *name, const FileInfo &info); + const ExcludeList &exclude_list, + const char *name, + const StorageFileInfo &info); - bool UpdateDirectory(Directory &directory, const FileInfo &info); + bool UpdateDirectory(Directory &directory, + const ExcludeList &exclude_list, + const StorageFileInfo &info); /** * Create the specified directory object if it does not exist @@ -142,7 +146,7 @@ private: * The caller must lock the database. */ Directory *MakeDirectoryIfModified(Directory &parent, const char *name, - const FileInfo &info); + const StorageFileInfo &info); Directory *DirectoryMakeChildChecked(Directory &parent, const char *uri_utf8, |