1081 |
1081 |
1082 // upload all changed files |
1082 // upload all changed files |
1083 //UcxList *resources = cmd_getoption(a, "read") ? |
1083 //UcxList *resources = cmd_getoption(a, "read") ? |
1084 // read_changes(dir, db) : local_scan(dir, db); |
1084 // read_changes(dir, db) : local_scan(dir, db); |
1085 UcxList *resources = local_scan(dir, db); |
1085 UcxList *resources = local_scan(dir, db); |
1086 |
1086 |
1087 UcxMap *lclres = ucx_map_new(db->resources->count); |
1087 UcxMap *lclres = ucx_map_new(db->resources->count); |
1088 int ret = 0; |
1088 int ret = 0; |
1089 UCX_FOREACH(elm, resources) { |
1089 UCX_FOREACH(elm, resources) { |
1090 LocalResource *local_res = elm->data; |
1090 LocalResource *local_res = elm->data; |
1091 int error = 0; |
1091 int error = 0; |
1143 print_resource_error(sn, local_res->path); |
1143 print_resource_error(sn, local_res->path); |
1144 ret = -1; |
1144 ret = -1; |
1145 sync_error++; |
1145 sync_error++; |
1146 } |
1146 } |
1147 |
1147 |
1148 if(local_res->isdirectory || !is_changed) { |
1148 if(local_res->isdirectory) { |
1149 // only check existence if the resource is supposed |
1149 dav_exists(res); |
1150 // to be a collection |
1150 if(sn->error == DAV_NOT_FOUND) { |
1151 int exists = local_res->isdirectory ? dav_exists(res) : 1; |
|
1152 |
|
1153 // continue if the resource exists or is not found |
|
1154 // because a 404 is not an unexpected error |
|
1155 if(exists || sn->error == DAV_NOT_FOUND) { |
|
1156 int abort = 0; |
1151 int abort = 0; |
1157 if(!exists) { |
1152 // make sure to store tags for newly created cols |
1158 // make sure to store tags for newly created cols |
1153 local_res->tags_updated = 1; |
1159 local_res->tags_updated = 1; |
1154 // create collection |
1160 // create collection |
1155 // TODO: show 405 |
1161 // TODO: show 405 |
1156 printf("mkcol: %s\n", local_res->path); |
1162 printf("mkcol: %s\n", local_res->path); |
1157 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { |
1163 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { |
1158 print_resource_error(sn, res->path); |
1164 print_resource_error(sn, res->path); |
1159 ret = -1; |
1165 ret = -1; |
1160 sync_error++; |
1166 sync_error++; |
1161 error = 1; |
1167 error = 1; |
1162 abort = 1; |
1168 abort = 1; |
|
1169 } |
|
1170 } |
1163 } |
1171 |
1164 |
1172 if(dir->tagconfig && local_res->tags_updated && !abort) { |
1165 if(dir->tagconfig && local_res->tags_updated && !abort) { |
1173 sync_update_tags(dir, sn, res, local_res); |
1166 sync_update_tags(dir, sn, res, local_res); |
1174 } |
1167 } |
1175 } else { |
1168 } else if(sn->error != DAV_OK) { |
1176 // dav_exists() failed |
1169 // dav_exists() failed |
1177 print_resource_error(sn, local_res->path); |
1170 print_resource_error(sn, local_res->path); |
1178 ret = -1; |
1171 ret = -1; |
1179 sync_error++; |
1172 sync_error++; |
1180 error = 1; |
1173 error = 1; |
|
1174 } |
|
1175 } else if(!is_changed) { |
|
1176 if(dir->tagconfig && local_res->tags_updated) { |
|
1177 sync_update_tags(dir, sn, res, local_res); |
1181 } |
1178 } |
1182 } else { |
1179 } else { |
1183 if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) { |
1180 if(cdt && remote_resource_is_changed(sn, dir, db, local_res)) { |
1184 printf("conflict: %s\n", local_res->path); |
1181 printf("conflict: %s\n", local_res->path); |
1185 local_res->last_modified = 0; |
1182 local_res->last_modified = 0; |