dav/sync.c

changeset 543
2f85df8cd35e
parent 542
060a8cda7f62
child 544
9e85e1ec1155
equal deleted inserted replaced
542:060a8cda7f62 543:2f85df8cd35e
282 return 1; 282 return 1;
283 } 283 }
284 free(rpath.ptr); 284 free(rpath.ptr);
285 } 285 }
286 286
287 // versioning filter
288 if (dir->versioning) {
289 if(util_path_isrelated(dir->versioning->collection, res_path)) {
290 return 1;
291 }
292 }
293
287 // include/exclude filter 294 // include/exclude filter
288 UCX_FOREACH(inc, dir->include) { 295 UCX_FOREACH(inc, dir->include) {
289 regex_t* pattern = (regex_t*) inc->data; 296 regex_t* pattern = (regex_t*) inc->data;
290 if (regexec(pattern, res_path, 0, NULL, 0) == 0) { 297 if (regexec(pattern, res_path, 0, NULL, 0) == 0) {
291 UCX_FOREACH(exc, dir->exclude) { 298 UCX_FOREACH(exc, dir->exclude) {
515 locked = TRUE; 522 locked = TRUE;
516 locktokenfile = create_locktoken_file(dir->name, lock->token); 523 locktokenfile = create_locktoken_file(dir->name, lock->token);
517 } 524 }
518 525
519 int ret = 0; 526 int ret = 0;
520 DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:content-hash from / with depth = infinity"); 527 DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,`idav:content-hash` from / with depth = infinity");
521 if(!ls) { 528 if(!ls) {
522 print_resource_error(sn, "/"); 529 print_resource_error(sn, "/");
523 if(locked) { 530 if(locked) {
524 if(dav_unlock(root)) { 531 if(dav_unlock(root)) {
525 print_resource_error(sn, "/"); 532 print_resource_error(sn, "/");
813 if(!etag) { 820 if(!etag) {
814 fprintf(stderr, "Error: resource %s has no etag\n", res->path); 821 fprintf(stderr, "Error: resource %s has no etag\n", res->path);
815 return REMOTE_NO_CHANGE; 822 return REMOTE_NO_CHANGE;
816 } 823 }
817 824
825 DavBool issplit = dav_get_property(res, "idav:split") ? TRUE : FALSE;
826
818 RemoteChangeType type = cmd_getoption(a, "conflict") ? 827 RemoteChangeType type = cmd_getoption(a, "conflict") ?
819 REMOTE_CHANGE_MODIFIED : REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED; 828 REMOTE_CHANGE_MODIFIED : REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED;
820 829
821 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); 830 LocalResource *local = ucx_map_cstr_get(db->resources, res->path);
822 char *local_path = util_concat_path(dir->path, res->path); 831 char *local_path = util_concat_path(dir->path, res->path);
831 } 840 }
832 exists = 0; 841 exists = 0;
833 } 842 }
834 843
835 RemoteChangeType ret = REMOTE_NO_CHANGE; 844 RemoteChangeType ret = REMOTE_NO_CHANGE;
836 if(res->iscollection) { 845 if(res->iscollection && !issplit) {
837 if(!exists) { 846 if(!exists) {
838 ret = REMOTE_CHANGE_MKDIR; 847 ret = REMOTE_CHANGE_MKDIR;
839 } 848 }
840 } else if(local) { 849 } else if(local) {
841 DavBool nochange = FALSE; 850 DavBool nochange = FALSE;
842 if(local->etag) { 851 char *content_hash = sync_get_content_hash(res);
852
853 if(content_hash || local->hash) {
854 if(!nullstrcmp(content_hash, local->hash)) {
855 nochange = TRUE;
856 }
857 } else if(local->etag) {
843 sstr_t e = sstr(etag); 858 sstr_t e = sstr(etag);
844 if(sstrprefix(e, S("W/"))) { 859 if(sstrprefix(e, S("W/"))) {
845 e = sstrsubs(e, 2); 860 e = sstrsubs(e, 2);
846 } 861 }
847 if(!strcmp(e.ptr, local->etag)) { 862 if(!strcmp(e.ptr, local->etag)) {
956 } 971 }
957 fclose(out); 972 fclose(out);
958 973
959 if(ret == 0) { 974 if(ret == 0) {
960 (*counter)++; 975 (*counter)++;
961
962 if(sync_store_metadata(dir, tmp_path, local, res)) {
963 fprintf(stderr, "Cannot store metadata: %s\n", path);
964 }
965 976
966 if(dir->trash && dir->backuppull) { 977 if(dir->trash && dir->backuppull) {
967 move_to_trash(dir, local_path); 978 move_to_trash(dir, local_path);
968 } 979 }
969 if(sys_rename(tmp_path, local_path)) { 980 if(sys_rename(tmp_path, local_path)) {
986 if(!local) { 997 if(!local) {
987 // new local resource 998 // new local resource
988 local = calloc(1, sizeof(LocalResource)); 999 local = calloc(1, sizeof(LocalResource));
989 local->path = strdup(path); 1000 local->path = strdup(path);
990 ucx_map_cstr_put(db->resources, local->path, local); 1001 ucx_map_cstr_put(db->resources, local->path, local);
1002 }
1003
1004 if(sync_store_metadata(dir, local_path, local, res)) {
1005 fprintf(stderr, "Cannot store metadata: %s\n", path);
991 } 1006 }
992 1007
993 if(local->etag) { 1008 if(local->etag) {
994 free(local->etag); 1009 free(local->etag);
995 } 1010 }

mercurial