dav/sync.c

changeset 389
fe855ce911f9
parent 386
99193580aa9d
child 390
26998dc980f9
equal deleted inserted replaced
388:0b96ae226838 389:fe855ce911f9
253 } 253 }
254 } 254 }
255 return 1; 255 return 1;
256 } 256 }
257 257
258 static int matches_tags(UcxList *resource_tags, UcxList *tags) { 258 static int matches_tags(UcxList *resource_tags, SyncTagFilter *tagfilter) {
259 if(!tags) {
260 return 1;
261 }
262 if(!resource_tags) { 259 if(!resource_tags) {
263 return 0; 260 return 0;
264 } 261 }
265 262
266 UcxMap *res_tagmap = ucx_map_new(32); 263 UcxMap *res_tagmap = ucx_map_new(32);
271 } 268 }
272 269
273 int ret = 1; 270 int ret = 1;
274 271
275 // TODO: replace FOREACH with new tag expression evaluation 272 // TODO: replace FOREACH with new tag expression evaluation
276 UCX_FOREACH(elm, tags) { 273 UCX_FOREACH(elm, tagfilter->tags) {
277 DavTag *matches_tag = elm->data; 274 DavTag *matches_tag = elm->data;
278 if(!ucx_map_cstr_get(res_tagmap, matches_tag->name)) { 275 if(!ucx_map_cstr_get(res_tagmap, matches_tag->name)) {
279 ret = 0; 276 ret = 0;
280 break; 277 break;
281 } 278 }
283 280
284 ucx_map_free(res_tagmap); 281 ucx_map_free(res_tagmap);
285 return ret; 282 return ret;
286 } 283 }
287 284
288 static int res_matches_tags(DavResource *res, UcxList *tags) { 285 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) {
289 if(!tags) { 286 if(!tagfilter) {
290 return 1; 287 return 1;
291 } 288 }
292 289
293 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); 290 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
294 UcxList *res_tags = parse_dav_xml_taglist(tagsprop); 291 UcxList *res_tags = parse_dav_xml_taglist(tagsprop);
295 292
296 int ret = matches_tags(res_tags, tags); 293 int ret = matches_tags(res_tags, tagfilter);
297 // TODO: free list content 294 // TODO: free list content
298 ucx_list_free(res_tags); 295 ucx_list_free(res_tags);
299 return ret; 296 return ret;
300 } 297 }
301 298
302 static int localres_matches_tags(LocalResource *res, UcxList *tags) { 299 static int localres_matches_tags(LocalResource *res, SyncTagFilter *tagfilter) {
300 if(!tagfilter) {
301 return 1;
302 }
303
303 // TODO: implement 304 // TODO: implement
304 return 1; 305 return 1;
305 } 306 }
306 307
307 static DavSession* create_session(DavContext *ctx, Repository *repo, char *url) { 308 static DavSession* create_session(DavContext *ctx, Repository *repo, char *url) {
452 } 453 }
453 454
454 return -1; 455 return -1;
455 } 456 }
456 457
457 UcxList *tags = NULL;
458 char *tags_str = cmd_getoption(a, "tags");
459 if(tags_str) {
460 tags = parse_csv_taglist(tags_str, strlen(tags_str));
461 }
462 DavBool rm_tagmismatch = cmd_getoption(a, "remove") ? 1 : 0;
463
464 int sync_success = 0; 458 int sync_success = 0;
465 int sync_delete = 0; 459 int sync_delete = 0;
466 int sync_error = 0; 460 int sync_error = 0;
467 461
468 UcxMap *svrres = ucx_map_new(db->resources->count); 462 UcxMap *svrres = ucx_map_new(db->resources->count);
478 if (res_matches_filter(dir, res->path)) { 472 if (res_matches_filter(dir, res->path)) {
479 res = res->next; 473 res = res->next;
480 continue; 474 continue;
481 } 475 }
482 476
483 if (!res_matches_tags(res, tags)) { 477
484 if(!rm_tagmismatch) { 478 SyncTagFilter tagfilter;
479 tagfilter.tags = NULL;
480 char *tags_str = cmd_getoption(a, "tags");
481 if(tags_str) {
482 tagfilter.tags = parse_csv_taglist(tags_str, strlen(tags_str));
483 }
484 if (!res_matches_tags(res, &tagfilter)) {
485 if(!cmd_getoption(a, "remove")) {
485 localres_keep(db, res->path); 486 localres_keep(db, res->path);
486 } 487 }
487 res = res->next; 488 res = res->next;
488 continue; 489 continue;
489 } 490 }

mercurial