Walk.hxx 4.48 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef MPD_UPDATE_WALK_HXX
#define MPD_UPDATE_WALK_HXX

#include "check.h"
#include "Editor.hxx"
25
#include "Compiler.h"
26

27 28
#include <atomic>

29
struct StorageFileInfo;
30
struct Directory;
31
struct ArchivePlugin;
32
class ArchiveFile;
33
class Storage;
34 35 36 37 38 39 40
class ExcludeList;

class UpdateWalk final {
#ifdef ENABLE_ARCHIVE
	friend class UpdateArchiveVisitor;
#endif

41
#ifndef _WIN32
42 43 44 45 46 47 48 49 50 51
	static constexpr bool DEFAULT_FOLLOW_INSIDE_SYMLINKS = true;
	static constexpr bool DEFAULT_FOLLOW_OUTSIDE_SYMLINKS = true;

	bool follow_inside_symlinks;
	bool follow_outside_symlinks;
#endif

	bool walk_discard;
	bool modified;

52 53 54 55 56
	/**
	 * Set to true by the main thread when the update thread shall
	 * cancel as quickly as possible.  Access to this flag is
	 * unprotected.
	 */
57
	std::atomic_bool cancel;
58

59
	Storage &storage;
60

61 62 63
	DatabaseEditor editor;

public:
64
	UpdateWalk(EventLoop &_loop, DatabaseListener &_listener,
65
		   Storage &_storage) noexcept;
66

67 68 69 70
	/**
	 * Cancel the current update and quit the Walk() method as
	 * soon as possible.
	 */
71
	void Cancel() noexcept {
72 73 74
		cancel = true;
	}

75 76 77
	/**
	 * Returns true if the database was modified.
	 */
78
	bool Walk(Directory &root, const char *path, bool discard) noexcept;
79 80 81 82

private:
	gcc_pure
	bool SkipSymlink(const Directory *directory,
83
			 const char *utf8_name) const noexcept;
84 85

	void RemoveExcludedFromDirectory(Directory &directory,
86
					 const ExcludeList &exclude_list) noexcept;
87

88
	void PurgeDeletedFromDirectory(Directory &directory) noexcept;
89 90 91

	void UpdateSongFile2(Directory &directory,
			     const char *name, const char *suffix,
92
			     const StorageFileInfo &info) noexcept;
93 94 95

	bool UpdateSongFile(Directory &directory,
			    const char *name, const char *suffix,
96
			    const StorageFileInfo &info) noexcept;
97 98 99

	bool UpdateContainerFile(Directory &directory,
				 const char *name, const char *suffix,
100
				 const StorageFileInfo &info) noexcept;
101 102 103


#ifdef ENABLE_ARCHIVE
104
	void UpdateArchiveTree(ArchiveFile &archive, Directory &parent,
105
			       const char *name) noexcept;
106 107 108

	bool UpdateArchiveFile(Directory &directory,
			       const char *name, const char *suffix,
109
			       const StorageFileInfo &info) noexcept;
110 111

	void UpdateArchiveFile(Directory &directory, const char *name,
112
			       const StorageFileInfo &info,
113
			       const ArchivePlugin &plugin) noexcept;
114 115 116 117 118 119


#else
	bool UpdateArchiveFile(gcc_unused Directory &directory,
			       gcc_unused const char *name,
			       gcc_unused const char *suffix,
120
			       gcc_unused const StorageFileInfo &info) noexcept {
121 122 123 124 125 126
		return false;
	}
#endif

	bool UpdatePlaylistFile(Directory &directory,
				const char *name, const char *suffix,
127
				const StorageFileInfo &info) noexcept;
128 129

	bool UpdateRegularFile(Directory &directory,
130
			       const char *name, const StorageFileInfo &info) noexcept;
131 132

	void UpdateDirectoryChild(Directory &directory,
133
				  const ExcludeList &exclude_list,
134
				  const char *name,
135
				  const StorageFileInfo &info) noexcept;
136

137
	bool UpdateDirectory(Directory &directory,
138
			     const ExcludeList &exclude_list,
139
			     const StorageFileInfo &info) noexcept;
140 141 142

	/**
	 * Create the specified directory object if it does not exist
143
	 * already or if the #StorageFileInfo object indicates that it has been
144 145 146 147 148 149
	 * modified since the last update.  Returns nullptr when it
	 * exists already and is unmodified.
	 *
	 * The caller must lock the database.
	 */
	Directory *MakeDirectoryIfModified(Directory &parent, const char *name,
150
					   const StorageFileInfo &info) noexcept;
151 152

	Directory *DirectoryMakeChildChecked(Directory &parent,
153
					     const char *uri_utf8,
154
					     const char *name_utf8) noexcept;
155

156
	Directory *DirectoryMakeUriParentChecked(Directory &root,
157
						 const char *uri) noexcept;
158

159
	void UpdateUri(Directory &root, const char *uri) noexcept;
160 161 162
};

#endif