diff -r 8bf1d9688698 -r fefe4b6f1048 dav/sync.c --- a/dav/sync.c Sat Sep 28 09:24:30 2019 +0200 +++ b/dav/sync.c Sun Sep 29 12:57:13 2019 +0200 @@ -299,7 +299,24 @@ return local_path; } -static int res_matches_filter(SyncDirectory *dir, char *res_path) { +static int res_matches_filter(Filter *filter, char *res_path) { + // include/exclude filter + UCX_FOREACH(inc, filter->include) { + regex_t* pattern = (regex_t*) inc->data; + if (regexec(pattern, res_path, 0, NULL, 0) == 0) { + UCX_FOREACH(exc, filter->exclude) { + regex_t* pattern = (regex_t*) exc->data; + if (regexec(pattern, res_path, 0, NULL, 0) == 0) { + return 1; + } + } + return 0; + } + } + return 1; +} + +static int res_matches_dir_filter(SyncDirectory *dir, char *res_path) { // trash filter if (dir->trash) { sstr_t rpath = sstr(util_concat_path(dir->path, res_path)); @@ -317,20 +334,7 @@ } } - // include/exclude filter - UCX_FOREACH(inc, dir->include) { - regex_t* pattern = (regex_t*) inc->data; - if (regexec(pattern, res_path, 0, NULL, 0) == 0) { - UCX_FOREACH(exc, dir->exclude) { - regex_t* pattern = (regex_t*) exc->data; - if (regexec(pattern, res_path, 0, NULL, 0) == 0) { - return 1; - } - } - return 0; - } - } - return 1; + return res_matches_filter(&dir->filter, res_path); } static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) { @@ -629,10 +633,10 @@ while(res) { DavBool res_filtered = FALSE; - if (res_matches_filter(dir, res->path)) { + if (res_matches_dir_filter(dir, res->path)) { res_filtered = TRUE; } else { - UCX_FOREACH(elm, dir->tagfilter) { + UCX_FOREACH(elm, dir->filter.tags) { SyncTagFilter *tf = elm->data; if(!res_matches_tags(res, tf)) { res_filtered = TRUE; @@ -712,7 +716,7 @@ UcxMapIterator i = ucx_map_iterator(dbres); LocalResource *local; UCX_MAP_FOREACH(key, local, i) { - if (res_matches_filter(dir, local->path)) { + if (res_matches_dir_filter(dir, local->path)) { continue; } if(!local->keep) { @@ -1854,11 +1858,11 @@ // ignore all files, that are excluded by a static filter (sync.xml) // static include/exclude filter - if(res_matches_filter(dir, local_res->path+1)) { + if(res_matches_dir_filter(dir, local_res->path+1)) { continue; } // static tag filter - UCX_FOREACH(elm, dir->tagfilter) { + UCX_FOREACH(elm, dir->filter.tags) { SyncTagFilter *tf = elm->data; if(!localres_matches_tags(dir, local_res, tf)) { continue; @@ -1970,11 +1974,11 @@ UcxList *removed_res = NULL; UCX_MAP_FOREACH(key, local, i) { // all filtered files should be removed from the database - if(res_matches_filter(dir, local->path+1)) { + if(res_matches_dir_filter(dir, local->path+1)) { ucx_map_cstr_remove(db->resources, local->path); continue; } - UCX_FOREACH(elm, dir->tagfilter) { + UCX_FOREACH(elm, dir->filter.tags) { SyncTagFilter *tf = elm->data; if(!localres_matches_tags(dir, local, tf)) { ucx_map_cstr_remove(db->resources, local->path); @@ -2989,8 +2993,8 @@ } else { UCX_FOREACH(elm, dir->splitconfig) { SplitConfig *sc = elm->data; - if(sc->pattern) { - if(regexec(sc->pattern, local->path, 0, NULL, 0) != 0) { + if(sc->filter) { + if(res_matches_filter(sc->filter, local->path)) { continue; } }