Walk.hxx 4.69 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2019 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
 * 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

23
#include "Config.hxx"
24
#include "Editor.hxx"
25
#include "util/Compiler.h"
26
#include "config.h"
27

28 29
#include <atomic>

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

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

42
	const UpdateConfig config;
43 44 45 46

	bool walk_discard;
	bool modified;

47 48 49 50 51
	/**
	 * Set to true by the main thread when the update thread shall
	 * cancel as quickly as possible.  Access to this flag is
	 * unprotected.
	 */
52
	std::atomic_bool cancel;
53

54
	Storage &storage;
55

56 57 58
	DatabaseEditor editor;

public:
59 60
	UpdateWalk(const UpdateConfig &_config,
		   EventLoop &_loop, DatabaseListener &_listener,
61
		   Storage &_storage) noexcept;
62

63 64 65 66
	/**
	 * Cancel the current update and quit the Walk() method as
	 * soon as possible.
	 */
67
	void Cancel() noexcept {
68 69 70
		cancel = true;
	}

71 72 73
	/**
	 * Returns true if the database was modified.
	 */
74
	bool Walk(Directory &root, const char *path, bool discard) noexcept;
75 76 77 78

private:
	gcc_pure
	bool SkipSymlink(const Directory *directory,
79
			 const char *utf8_name) const noexcept;
80 81

	void RemoveExcludedFromDirectory(Directory &directory,
82
					 const ExcludeList &exclude_list) noexcept;
83

84
	void PurgeDeletedFromDirectory(Directory &directory) noexcept;
85 86 87

	void UpdateSongFile2(Directory &directory,
			     const char *name, const char *suffix,
88
			     const StorageFileInfo &info) noexcept;
89 90 91

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

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


#ifdef ENABLE_ARCHIVE
100
	void UpdateArchiveTree(ArchiveFile &archive, Directory &parent,
101
			       const char *name) noexcept;
102 103 104

	bool UpdateArchiveFile(Directory &directory,
			       const char *name, const char *suffix,
105
			       const StorageFileInfo &info) noexcept;
106 107

	void UpdateArchiveFile(Directory &directory, const char *name,
108
			       const StorageFileInfo &info,
109
			       const ArchivePlugin &plugin) noexcept;
110 111 112 113 114 115


#else
	bool UpdateArchiveFile(gcc_unused Directory &directory,
			       gcc_unused const char *name,
			       gcc_unused const char *suffix,
116
			       gcc_unused const StorageFileInfo &info) noexcept {
117 118 119 120 121 122
		return false;
	}
#endif

	bool UpdatePlaylistFile(Directory &directory,
				const char *name, const char *suffix,
123
				const StorageFileInfo &info) noexcept;
124 125

	bool UpdateRegularFile(Directory &directory,
126
			       const char *name, const StorageFileInfo &info) noexcept;
127 128

	void UpdateDirectoryChild(Directory &directory,
129
				  const ExcludeList &exclude_list,
130
				  const char *name,
131
				  const StorageFileInfo &info) noexcept;
132

133
	bool UpdateDirectory(Directory &directory,
134
			     const ExcludeList &exclude_list,
135
			     const StorageFileInfo &info) noexcept;
136 137 138

	/**
	 * Create the specified directory object if it does not exist
139
	 * already or if the #StorageFileInfo object indicates that it has been
140 141 142 143
	 * modified since the last update.  Returns nullptr when it
	 * exists already and is unmodified.
	 *
	 * The caller must lock the database.
144 145 146
	 *
	 * @param virtual_device one of the DEVICE_* constants
	 * specifying the kind of virtual directory
147
	 */
148 149
	Directory *MakeVirtualDirectoryIfModified(Directory &parent,
						  const char *name,
150 151
						  const StorageFileInfo &info,
						  unsigned virtual_device) noexcept;
152

153 154 155 156 157
	Directory *LockMakeVirtualDirectoryIfModified(Directory &parent,
						      const char *name,
						      const StorageFileInfo &info,
						      unsigned virtual_device) noexcept;

158
	Directory *DirectoryMakeChildChecked(Directory &parent,
159
					     const char *uri_utf8,
160
					     const char *name_utf8) noexcept;
161

162
	Directory *DirectoryMakeUriParentChecked(Directory &root,
163
						 const char *uri) noexcept;
164

165
	void UpdateUri(Directory &root, const char *uri) noexcept;
166 167 168
};

#endif