Skip to content

Commit

Permalink
[scan] partial scan ensure's watchers removed/readded for scanned dir
Browse files Browse the repository at this point in the history
  • Loading branch information
whatdoineed2do/Ray committed Jan 29, 2021
1 parent f008e08 commit 0f216d5
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions src/library/filescanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,59 @@ watches_clear(uint32_t wd, char *path)
return 0;
}

static int
watches_clear_bypath(char *path)
{
struct watch_info wi;
struct watch_enum we;
int ret;

memset(&wi, 0, sizeof(struct watch_info));

wi.path = path;
db_watch_get_bypath(&wi);
watches_clear(wi.wd, path);
free(wi.path);

memset(&we, 0, sizeof(struct watch_enum));
we.match = ""; // get everything

ret = db_watch_enum_start(&we);
if (ret < 0)
return -1;

memset(&wi, 0, sizeof(struct watch_info));
wi.path = malloc(PATH_MAX);
while (db_watch_enum_fetch(&we, &wi) == 0 && wi.wd)
{
inotify_rm_watch(inofd, wi.wd);
db_watch_delete_bypath(wi.path);

#ifdef __linux__
wi.wd = inotify_add_watch(inofd, wi.path, IN_ATTRIB | IN_CREATE | IN_DELETE | IN_CLOSE_WRITE | IN_MOVE | IN_DELETE | IN_MOVE_SELF);
#else
wi.wd = inotify_add_watch(inofd, wi.path, IN_CREATE | IN_DELETE | IN_MOVE);
#endif
if (wi.wd < 0)
{
DPRINTF(E_LOG, L_SCAN, "Failed to obtain watch: '%s' - %s\n", wi.path, strerror(errno));
}
else
{
wi.cookie = 0;
db_watch_add(&wi);
}

wi.wd = 0;
wi.path[0] = '\0';
}

db_watch_enum_end(&we);

free(wi.path);
return 0;
}

/* Thread: scan */
static void
process_inotify_dir(struct watch_info *wi, char *path, struct inotify_event *ie)
Expand Down Expand Up @@ -1724,8 +1777,11 @@ filescanner_rescan_path(const char *path)
{
DPRINTF(E_LOG, L_SCAN, "rescan triggered for '%s'\n", path);

db_watch_delete_bypath((char*)path);
db_watch_delete_bymatch((char*)path);
inofd_event_unset(); // Clears all inotify watches, closing hdl
inofd_event_set(); // and get a new inotify hdl

// readd watchers but exclude path and let the bulk_scan to readd
watches_clear_bypath((char*)path);
bulk_scan(path, F_SCAN_BULK | F_SCAN_RESCAN);

if (!library_is_exiting())
Expand Down

0 comments on commit 0f216d5

Please sign in to comment.