Commit 393bcd96 authored by Max Kellermann's avatar Max Kellermann

inotify: added setting "auto_update_depth"

Limits the depth of the watched directories. This is useful to keep resource usage down and speed up MPD startup.
parent 4d1eedba
...@@ -253,6 +253,10 @@ comments. ...@@ -253,6 +253,10 @@ comments.
This specifies the wheter to support automatic update of music database when This specifies the wheter to support automatic update of music database when
files are changed in music_directory. The default is to disable autoupdate files are changed in music_directory. The default is to disable autoupdate
of database. of database.
.TP
.B auto_update_depth <N>
Limit the depth of the directories being watched, 0 means only watch
the music directory itself. There is no limit by default.
.SH REQUIRED AUDIO OUTPUT PARAMETERS .SH REQUIRED AUDIO OUTPUT PARAMETERS
.TP .TP
.B type <type> .B type <type>
......
...@@ -118,6 +118,12 @@ ...@@ -118,6 +118,12 @@
# music_directory are changed. # music_directory are changed.
# #
#auto_update "yes" #auto_update "yes"
#
# Limit the depth of the directories being watched, 0 means only watch
# the music directory itself. There is no limit by default.
#
#auto_update_depth "3"
#
############################################################################### ###############################################################################
......
...@@ -94,6 +94,7 @@ static struct config_entry config_entries[] = { ...@@ -94,6 +94,7 @@ static struct config_entry config_entries[] = {
{ .name = CONF_GAPLESS_MP3_PLAYBACK, false, false }, { .name = CONF_GAPLESS_MP3_PLAYBACK, false, false },
{ .name = CONF_PLAYLIST_PLUGIN, true, true }, { .name = CONF_PLAYLIST_PLUGIN, true, true },
{ .name = CONF_AUTO_UPDATE, false, false }, { .name = CONF_AUTO_UPDATE, false, false },
{ .name = CONF_AUTO_UPDATE_DEPTH, false, false },
{ .name = "filter", true, true }, { .name = "filter", true, true },
}; };
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
#define CONF_GAPLESS_MP3_PLAYBACK "gapless_mp3_playback" #define CONF_GAPLESS_MP3_PLAYBACK "gapless_mp3_playback"
#define CONF_PLAYLIST_PLUGIN "playlist_plugin" #define CONF_PLAYLIST_PLUGIN "playlist_plugin"
#define CONF_AUTO_UPDATE "auto_update" #define CONF_AUTO_UPDATE "auto_update"
#define CONF_AUTO_UPDATE_DEPTH "auto_update_depth"
#define DEFAULT_PLAYLIST_MAX_LENGTH (1024*16) #define DEFAULT_PLAYLIST_MAX_LENGTH (1024*16)
#define DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS false #define DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS false
......
...@@ -56,6 +56,7 @@ struct watch_directory { ...@@ -56,6 +56,7 @@ struct watch_directory {
static struct mpd_inotify_source *inotify_source; static struct mpd_inotify_source *inotify_source;
static unsigned inotify_max_depth;
static struct watch_directory inotify_root; static struct watch_directory inotify_root;
static GTree *inotify_directories; static GTree *inotify_directories;
...@@ -140,15 +141,21 @@ static bool skip_path(const char *path) ...@@ -140,15 +141,21 @@ static bool skip_path(const char *path)
static void static void
recursive_watch_subdirectories(struct watch_directory *directory, recursive_watch_subdirectories(struct watch_directory *directory,
const char *path_fs) const char *path_fs, unsigned depth)
{ {
GError *error = NULL; GError *error = NULL;
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
assert(directory != NULL); assert(directory != NULL);
assert(depth <= inotify_max_depth);
assert(path_fs != NULL); assert(path_fs != NULL);
++depth;
if (depth > inotify_max_depth)
return;
dir = opendir(path_fs); dir = opendir(path_fs);
if (dir == NULL) { if (dir == NULL) {
g_warning("Failed to open directory %s: %s", g_warning("Failed to open directory %s: %s",
...@@ -209,13 +216,26 @@ recursive_watch_subdirectories(struct watch_directory *directory, ...@@ -209,13 +216,26 @@ recursive_watch_subdirectories(struct watch_directory *directory,
tree_add_watch_directory(child); tree_add_watch_directory(child);
recursive_watch_subdirectories(child, child_path_fs); recursive_watch_subdirectories(child, child_path_fs, depth);
g_free(child_path_fs); g_free(child_path_fs);
} }
closedir(dir); closedir(dir);
} }
G_GNUC_PURE
static unsigned
watch_directory_depth(const struct watch_directory *d)
{
assert(d != NULL);
unsigned depth = 0;
while ((d = d->parent) != NULL)
++depth;
return depth;
}
static void static void
mpd_inotify_callback(int wd, unsigned mask, mpd_inotify_callback(int wd, unsigned mask,
G_GNUC_UNUSED const char *name, G_GNUC_UNUSED void *ctx) G_GNUC_UNUSED const char *name, G_GNUC_UNUSED void *ctx)
...@@ -250,7 +270,8 @@ mpd_inotify_callback(int wd, unsigned mask, ...@@ -250,7 +270,8 @@ mpd_inotify_callback(int wd, unsigned mask,
} else } else
path_fs = root; path_fs = root;
recursive_watch_subdirectories(directory, path_fs); recursive_watch_subdirectories(directory, path_fs,
watch_directory_depth(directory));
g_free(path_fs); g_free(path_fs);
} }
...@@ -271,7 +292,7 @@ mpd_inotify_callback(int wd, unsigned mask, ...@@ -271,7 +292,7 @@ mpd_inotify_callback(int wd, unsigned mask,
} }
void void
mpd_inotify_init(void) mpd_inotify_init(unsigned max_depth)
{ {
struct directory *root; struct directory *root;
char *path; char *path;
...@@ -300,6 +321,8 @@ mpd_inotify_init(void) ...@@ -300,6 +321,8 @@ mpd_inotify_init(void)
return; return;
} }
inotify_max_depth = max_depth;
inotify_root.name = path; inotify_root.name = path;
inotify_root.descriptor = mpd_inotify_source_add(inotify_source, path, inotify_root.descriptor = mpd_inotify_source_add(inotify_source, path,
IN_MASK, &error); IN_MASK, &error);
...@@ -315,7 +338,7 @@ mpd_inotify_init(void) ...@@ -315,7 +338,7 @@ mpd_inotify_init(void)
inotify_directories = g_tree_new(compare); inotify_directories = g_tree_new(compare);
tree_add_watch_directory(&inotify_root); tree_add_watch_directory(&inotify_root);
recursive_watch_subdirectories(&inotify_root, path); recursive_watch_subdirectories(&inotify_root, path, 0);
mpd_inotify_queue_init(); mpd_inotify_queue_init();
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifdef HAVE_INOTIFY_INIT #ifdef HAVE_INOTIFY_INIT
void void
mpd_inotify_init(void); mpd_inotify_init(unsigned max_depth);
void void
mpd_inotify_finish(void); mpd_inotify_finish(void);
...@@ -33,7 +33,7 @@ mpd_inotify_finish(void); ...@@ -33,7 +33,7 @@ mpd_inotify_finish(void);
#else /* !HAVE_INOTIFY_INIT */ #else /* !HAVE_INOTIFY_INIT */
static inline void static inline void
mpd_inotify_init(void) mpd_inotify_init(G_GNUC_UNUSED unsigned max_depth)
{ {
} }
......
...@@ -379,7 +379,8 @@ int main(int argc, char *argv[]) ...@@ -379,7 +379,8 @@ int main(int argc, char *argv[])
success = config_get_bool(CONF_AUTO_UPDATE, false); success = config_get_bool(CONF_AUTO_UPDATE, false);
#ifdef ENABLE_INOTIFY #ifdef ENABLE_INOTIFY
if (success && mapper_has_music_directory()) if (success && mapper_has_music_directory())
mpd_inotify_init(); mpd_inotify_init(config_get_unsigned(CONF_AUTO_UPDATE_DEPTH,
G_MAXUINT));
#else #else
if (success) if (success)
g_warning("inotify: auto_update was disabled. enable during compilation phase"); g_warning("inotify: auto_update was disabled. enable during compilation phase");
......
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