monitor: Fix directory symlink deletion handling
When a symlink to a direcotry is deleted inotify cannot tell it from a regular file rendering all its children orphans. This sometimes leads to an unexpected effect - they may appear later in a newly created directory when it gets an id used by the deleted symlink.
This commit is contained in:
parent
0a6e10e821
commit
c5c4d9e169
24
monitor.c
24
monitor.c
@ -366,21 +366,13 @@ monitor_insert_directory(int fd, char *name, const char * path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
monitor_remove_directory(int fd, const char * path)
|
monitor_remove_tree(const char * path)
|
||||||
{
|
{
|
||||||
char * sql;
|
char * sql;
|
||||||
char **result;
|
char **result;
|
||||||
int64_t detailID = 0;
|
int64_t detailID = 0;
|
||||||
int rows, i, ret = 1;
|
int rows, i, ret = 1;
|
||||||
|
|
||||||
/* Invalidate the scanner cache so we don't insert files into non-existent containers */
|
|
||||||
valid_cache = 0;
|
|
||||||
#ifdef HAVE_WATCH
|
|
||||||
if( fd > 0 )
|
|
||||||
{
|
|
||||||
monitor_remove_watch(fd, path);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
sql = sqlite3_mprintf("SELECT ID from DETAILS where (PATH > '%q/' and PATH <= '%q/%c')"
|
sql = sqlite3_mprintf("SELECT ID from DETAILS where (PATH > '%q/' and PATH <= '%q/%c')"
|
||||||
" or PATH = '%q'", path, path, 0xFF, path);
|
" or PATH = '%q'", path, path, 0xFF, path);
|
||||||
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) )
|
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) )
|
||||||
@ -403,3 +395,17 @@ monitor_remove_directory(int fd, const char * path)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
monitor_remove_directory(int fd, const char * path)
|
||||||
|
{
|
||||||
|
/* Invalidate the scanner cache so we don't insert files into non-existent containers */
|
||||||
|
valid_cache = 0;
|
||||||
|
#ifdef HAVE_WATCH
|
||||||
|
if( fd > 0 )
|
||||||
|
{
|
||||||
|
monitor_remove_watch(fd, path);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return monitor_remove_tree(path);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
int monitor_insert_file(const char *name, const char *path);
|
int monitor_insert_file(const char *name, const char *path);
|
||||||
int monitor_insert_directory(int fd, char *name, const char * path);
|
int monitor_insert_directory(int fd, char *name, const char * path);
|
||||||
int monitor_remove_file(const char * path);
|
int monitor_remove_file(const char * path);
|
||||||
|
int monitor_remove_tree(const char * path);
|
||||||
int monitor_remove_directory(int fd, const char * path);
|
int monitor_remove_directory(int fd, const char * path);
|
||||||
|
|
||||||
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
||||||
|
@ -366,7 +366,16 @@ inotify_thread(void *arg)
|
|||||||
if ( event->mask & IN_ISDIR )
|
if ( event->mask & IN_ISDIR )
|
||||||
monitor_remove_directory(pollfds[0].fd, path_buf);
|
monitor_remove_directory(pollfds[0].fd, path_buf);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
monitor_remove_file(path_buf);
|
monitor_remove_file(path_buf);
|
||||||
|
/*
|
||||||
|
* When a symlink to a directory is deleted
|
||||||
|
* we cannot tell it from a regular file deletion
|
||||||
|
* to prevent its children from becoming orphans
|
||||||
|
* we delete the whole tree when it exists
|
||||||
|
*/
|
||||||
|
monitor_remove_tree(path_buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(esc_name);
|
free(esc_name);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user