Commit f7d8e6c4 authored by Max Kellermann's avatar Max Kellermann

InotifyUpdate: allocate the root dynamically

parent 4ecf09f9
...@@ -56,7 +56,6 @@ struct WatchDirectory { ...@@ -56,7 +56,6 @@ struct WatchDirectory {
GList *children; GList *children;
WatchDirectory() = default;
WatchDirectory(WatchDirectory *_parent, const char *_name, WatchDirectory(WatchDirectory *_parent, const char *_name,
int _descriptor) int _descriptor)
:parent(_parent), name(g_strdup(_name)), :parent(_parent), name(g_strdup(_name)),
...@@ -68,7 +67,7 @@ static InotifySource *inotify_source; ...@@ -68,7 +67,7 @@ static InotifySource *inotify_source;
static InotifyQueue *inotify_queue; static InotifyQueue *inotify_queue;
static unsigned inotify_max_depth; static unsigned inotify_max_depth;
static WatchDirectory inotify_root; static WatchDirectory *inotify_root;
static std::map<int, WatchDirectory *> inotify_directories; static std::map<int, WatchDirectory *> inotify_directories;
static void static void
...@@ -322,10 +321,8 @@ mpd_inotify_init(unsigned max_depth) ...@@ -322,10 +321,8 @@ mpd_inotify_init(unsigned max_depth)
inotify_max_depth = max_depth; inotify_max_depth = max_depth;
inotify_root.name = g_strdup(path.c_str()); int descriptor = inotify_source->Add(path.c_str(), IN_MASK, &error);
inotify_root.descriptor = inotify_source->Add(path.c_str(), if (descriptor < 0) {
IN_MASK, &error);
if (inotify_root.descriptor < 0) {
g_warning("%s", error->message); g_warning("%s", error->message);
g_error_free(error); g_error_free(error);
delete inotify_source; delete inotify_source;
...@@ -333,9 +330,11 @@ mpd_inotify_init(unsigned max_depth) ...@@ -333,9 +330,11 @@ mpd_inotify_init(unsigned max_depth)
return; return;
} }
tree_add_watch_directory(&inotify_root); inotify_root = new WatchDirectory(nullptr, path.c_str(), descriptor);
recursive_watch_subdirectories(&inotify_root, path.c_str(), 0); tree_add_watch_directory(inotify_root);
recursive_watch_subdirectories(inotify_root, path.c_str(), 0);
inotify_queue = new InotifyQueue(*main_loop); inotify_queue = new InotifyQueue(*main_loop);
...@@ -357,8 +356,7 @@ mpd_inotify_finish(void) ...@@ -357,8 +356,7 @@ mpd_inotify_finish(void)
g_free(directory->name); g_free(directory->name);
g_list_free(directory->children); g_list_free(directory->children);
if (directory != &inotify_root) delete directory;
delete directory;
} }
inotify_directories.clear(); inotify_directories.clear();
......
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