dav/sync.c

changeset 366
5228b912c925
parent 363
e9ed8e130ccf
child 367
4a6a59f89f9f
equal deleted inserted replaced
365:f04ab0420512 366:5228b912c925
581 if(!local) { 581 if(!local) {
582 // new local resource 582 // new local resource
583 local = calloc(1, sizeof(LocalResource)); 583 local = calloc(1, sizeof(LocalResource));
584 local->path = util_concat_path(res->path, "/"); 584 local->path = util_concat_path(res->path, "/");
585 local->last_modified = 0; 585 local->last_modified = 0;
586 if(local->etag) {
587 free(local->etag);
588 }
589 local->etag = strdup(etag);
586 ucx_map_cstr_put(db->resources, local->path, local); 590 ucx_map_cstr_put(db->resources, local->path, local);
587 } 591 }
588 592
589 sync_store_tags(dir, local_path, local, res); 593 sync_store_tags(dir, local_path, local, res);
590 } 594 }
931 continue; 935 continue;
932 } 936 }
933 937
934 // upload every changed file 938 // upload every changed file
935 int error = 0; 939 int error = 0;
936 if (local_resource_is_changed(dir, db, local_res)) { 940 int is_changed = local_resource_is_changed(dir, db, local_res);
941 if (is_changed || local_res->tags_updated) {
937 DavResource *res = dav_resource_new(sn, local_res->path); 942 DavResource *res = dav_resource_new(sn, local_res->path);
938 if(!res) { 943 if(!res) {
939 print_resource_error(sn, local_res->path); 944 print_resource_error(sn, local_res->path);
940 ret = -1; 945 ret = -1;
941 sync_error++; 946 sync_error++;
942 } 947 }
943 948
944 if(local_res->isdirectory) { 949 if(local_res->isdirectory || !is_changed) {
945 printf("mkcol: %s\n", local_res->path); 950 // only check existence if the resource is supposed
946 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { 951 // to be a collection
947 print_resource_error(sn, res->path); 952 int exists = local_res->isdirectory ? dav_exists(res) : 1;
953
954 // continue if the resource exists or is not found
955 // because a 404 is not an unexpected error
956 if(exists || sn->error == DAV_NOT_FOUND) {
957 int abort = 0;
958 if(!exists) {
959 // make sure to store tags for newly created cols
960 local_res->tags_updated = 1;
961 // create collection
962 // TODO: show 405
963 printf("mkcol: %s\n", local_res->path);
964 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) {
965 print_resource_error(sn, res->path);
966 ret = -1;
967 sync_error++;
968 error = 1;
969 abort = 1;
970 }
971 }
972
973 if(dir->tagconfig && local_res->tags_updated && !abort) {
974 // get tags from tagstore (xattr or something else)
975 // and store it in resource property
976 UcxList *tags = sync_get_file_tags(dir, local_res);
977 DavXmlNode *prop = create_xml_taglist(tags);
978 if(prop) {
979 dav_set_property_ns(res, DAV_NS, "tags", prop);
980 printf("update: %s\n", local_res->path);
981 if(dav_store(res)) {
982 print_resource_error(sn, local_res->path);
983 ret = -1;
984 sync_error++;
985 } else {
986 sync_success++;
987 local_res->tags_updated = 0;
988 }
989 }
990 }
991 } else {
992 // dav_exists() failed
993 print_resource_error(sn, local_res->path);
948 ret = -1; 994 ret = -1;
949 sync_error++; 995 sync_error++;
950 error = 1; 996 error = 1;
951 } 997 }
952 } else { 998 } else {
1192 return newres; 1238 return newres;
1193 } 1239 }
1194 1240
1195 int local_resource_is_changed(SyncDirectory *dir, SyncDatabase *db, LocalResource *res) { 1241 int local_resource_is_changed(SyncDirectory *dir, SyncDatabase *db, LocalResource *res) {
1196 LocalResource *db_res = ucx_map_cstr_get(db->resources, res->path); 1242 LocalResource *db_res = ucx_map_cstr_get(db->resources, res->path);
1243 res->tags_updated = 0;
1197 if(db_res) { 1244 if(db_res) {
1245 res->tags_updated = db_res->tags_updated;
1198 if(db_res->etag) { 1246 if(db_res->etag) {
1199 res->etag = strdup(db_res->etag); 1247 res->etag = strdup(db_res->etag);
1200 } 1248 }
1201 1249
1202 if(db_res->last_modified == res->last_modified && db_res->size == res->size) { 1250 if(db_res->last_modified == res->last_modified && db_res->size == res->size) {

mercurial