297 local_path[local_path_len-1] = '\0'; |
297 local_path[local_path_len-1] = '\0'; |
298 } |
298 } |
299 return local_path; |
299 return local_path; |
300 } |
300 } |
301 |
301 |
302 static int res_matches_filter(SyncDirectory *dir, char *res_path) { |
302 static int res_matches_filter(Filter *filter, char *res_path) { |
|
303 // include/exclude filter |
|
304 UCX_FOREACH(inc, filter->include) { |
|
305 regex_t* pattern = (regex_t*) inc->data; |
|
306 if (regexec(pattern, res_path, 0, NULL, 0) == 0) { |
|
307 UCX_FOREACH(exc, filter->exclude) { |
|
308 regex_t* pattern = (regex_t*) exc->data; |
|
309 if (regexec(pattern, res_path, 0, NULL, 0) == 0) { |
|
310 return 1; |
|
311 } |
|
312 } |
|
313 return 0; |
|
314 } |
|
315 } |
|
316 return 1; |
|
317 } |
|
318 |
|
319 static int res_matches_dir_filter(SyncDirectory *dir, char *res_path) { |
303 // trash filter |
320 // trash filter |
304 if (dir->trash) { |
321 if (dir->trash) { |
305 sstr_t rpath = sstr(util_concat_path(dir->path, res_path)); |
322 sstr_t rpath = sstr(util_concat_path(dir->path, res_path)); |
306 if (util_path_isrelated(dir->trash, rpath.ptr)) { |
323 if (util_path_isrelated(dir->trash, rpath.ptr)) { |
307 free(rpath.ptr); |
324 free(rpath.ptr); |
315 if(util_path_isrelated(dir->versioning->collection, res_path)) { |
332 if(util_path_isrelated(dir->versioning->collection, res_path)) { |
316 return 1; |
333 return 1; |
317 } |
334 } |
318 } |
335 } |
319 |
336 |
320 // include/exclude filter |
337 return res_matches_filter(&dir->filter, res_path); |
321 UCX_FOREACH(inc, dir->include) { |
|
322 regex_t* pattern = (regex_t*) inc->data; |
|
323 if (regexec(pattern, res_path, 0, NULL, 0) == 0) { |
|
324 UCX_FOREACH(exc, dir->exclude) { |
|
325 regex_t* pattern = (regex_t*) exc->data; |
|
326 if (regexec(pattern, res_path, 0, NULL, 0) == 0) { |
|
327 return 1; |
|
328 } |
|
329 } |
|
330 return 0; |
|
331 } |
|
332 } |
|
333 return 1; |
|
334 } |
338 } |
335 |
339 |
336 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) { |
340 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) { |
337 if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) { |
341 if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) { |
338 return 1; |
342 return 1; |
627 DavResource *res = stack->data; |
631 DavResource *res = stack->data; |
628 stack = ucx_list_remove(stack, stack); |
632 stack = ucx_list_remove(stack, stack); |
629 |
633 |
630 while(res) { |
634 while(res) { |
631 DavBool res_filtered = FALSE; |
635 DavBool res_filtered = FALSE; |
632 if (res_matches_filter(dir, res->path)) { |
636 if (res_matches_dir_filter(dir, res->path)) { |
633 res_filtered = TRUE; |
637 res_filtered = TRUE; |
634 } else { |
638 } else { |
635 UCX_FOREACH(elm, dir->tagfilter) { |
639 UCX_FOREACH(elm, dir->filter.tags) { |
636 SyncTagFilter *tf = elm->data; |
640 SyncTagFilter *tf = elm->data; |
637 if(!res_matches_tags(res, tf)) { |
641 if(!res_matches_tags(res, tf)) { |
638 res_filtered = TRUE; |
642 res_filtered = TRUE; |
639 break; |
643 break; |
640 } |
644 } |
710 // svrres currently contains all resources from the server |
714 // svrres currently contains all resources from the server |
711 // and will replace the current db->resources map later |
715 // and will replace the current db->resources map later |
712 UcxMapIterator i = ucx_map_iterator(dbres); |
716 UcxMapIterator i = ucx_map_iterator(dbres); |
713 LocalResource *local; |
717 LocalResource *local; |
714 UCX_MAP_FOREACH(key, local, i) { |
718 UCX_MAP_FOREACH(key, local, i) { |
715 if (res_matches_filter(dir, local->path)) { |
719 if (res_matches_dir_filter(dir, local->path)) { |
716 continue; |
720 continue; |
717 } |
721 } |
718 if(!local->keep) { |
722 if(!local->keep) { |
719 ucx_map_cstr_put(lres_removed, local->path, local); |
723 ucx_map_cstr_put(lres_removed, local->path, local); |
720 if(lres_removed->count > lres_removed->size * 2) { |
724 if(lres_removed->count > lres_removed->size * 2) { |
1852 UCX_FOREACH(elm, resources) { |
1856 UCX_FOREACH(elm, resources) { |
1853 LocalResource *local_res = elm->data; |
1857 LocalResource *local_res = elm->data; |
1854 // ignore all files, that are excluded by a static filter (sync.xml) |
1858 // ignore all files, that are excluded by a static filter (sync.xml) |
1855 |
1859 |
1856 // static include/exclude filter |
1860 // static include/exclude filter |
1857 if(res_matches_filter(dir, local_res->path+1)) { |
1861 if(res_matches_dir_filter(dir, local_res->path+1)) { |
1858 continue; |
1862 continue; |
1859 } |
1863 } |
1860 // static tag filter |
1864 // static tag filter |
1861 UCX_FOREACH(elm, dir->tagfilter) { |
1865 UCX_FOREACH(elm, dir->filter.tags) { |
1862 SyncTagFilter *tf = elm->data; |
1866 SyncTagFilter *tf = elm->data; |
1863 if(!localres_matches_tags(dir, local_res, tf)) { |
1867 if(!localres_matches_tags(dir, local_res, tf)) { |
1864 continue; |
1868 continue; |
1865 } |
1869 } |
1866 } |
1870 } |
1968 UcxMapIterator i = ucx_map_iterator(db->resources); |
1972 UcxMapIterator i = ucx_map_iterator(db->resources); |
1969 LocalResource *local; |
1973 LocalResource *local; |
1970 UcxList *removed_res = NULL; |
1974 UcxList *removed_res = NULL; |
1971 UCX_MAP_FOREACH(key, local, i) { |
1975 UCX_MAP_FOREACH(key, local, i) { |
1972 // all filtered files should be removed from the database |
1976 // all filtered files should be removed from the database |
1973 if(res_matches_filter(dir, local->path+1)) { |
1977 if(res_matches_dir_filter(dir, local->path+1)) { |
1974 ucx_map_cstr_remove(db->resources, local->path); |
1978 ucx_map_cstr_remove(db->resources, local->path); |
1975 continue; |
1979 continue; |
1976 } |
1980 } |
1977 UCX_FOREACH(elm, dir->tagfilter) { |
1981 UCX_FOREACH(elm, dir->filter.tags) { |
1978 SyncTagFilter *tf = elm->data; |
1982 SyncTagFilter *tf = elm->data; |
1979 if(!localres_matches_tags(dir, local, tf)) { |
1983 if(!localres_matches_tags(dir, local, tf)) { |
1980 ucx_map_cstr_remove(db->resources, local->path); |
1984 ucx_map_cstr_remove(db->resources, local->path); |
1981 continue; |
1985 continue; |
1982 } |
1986 } |
2987 } else if(local->blocksize > 0) { |
2991 } else if(local->blocksize > 0) { |
2988 local_blocksize = (size_t)local->blocksize; |
2992 local_blocksize = (size_t)local->blocksize; |
2989 } else { |
2993 } else { |
2990 UCX_FOREACH(elm, dir->splitconfig) { |
2994 UCX_FOREACH(elm, dir->splitconfig) { |
2991 SplitConfig *sc = elm->data; |
2995 SplitConfig *sc = elm->data; |
2992 if(sc->pattern) { |
2996 if(sc->filter) { |
2993 if(regexec(sc->pattern, local->path, 0, NULL, 0) != 0) { |
2997 if(res_matches_filter(sc->filter, local->path)) { |
2994 continue; |
2998 continue; |
2995 } |
2999 } |
2996 } |
3000 } |
2997 |
3001 |
2998 if(sc->minsize > 0) { |
3002 if(sc->minsize > 0) { |