4003 free(local_path); |
4003 free(local_path); |
4004 return -1; |
4004 return -1; |
4005 } |
4005 } |
4006 |
4006 |
4007 MetadataHashes hashes; |
4007 MetadataHashes hashes; |
4008 hashes = sync_set_metadata_properties(dir, res->session, res, local); |
4008 hashes = sync_set_metadata_properties(dir, res->session, res, local, FALSE); |
4009 |
4009 |
4010 // before sync_put_resource, remote_resource_is_changed does a propfind |
4010 // before sync_put_resource, remote_resource_is_changed does a propfind |
4011 // and sets res->exists |
4011 // and sets res->exists |
4012 int exists = res->exists; |
4012 int exists = res->exists; |
4013 if(dir->versioning && dir->versioning->always && !issplit) { |
4013 if(dir->versioning && dir->versioning->always && !issplit) { |
4133 |
4133 |
4134 LocalResource *local_origin = local->origin; |
4134 LocalResource *local_origin = local->origin; |
4135 if(!copy) { |
4135 if(!copy) { |
4136 ucx_map_cstr_remove(db->resources, local_origin->path); |
4136 ucx_map_cstr_remove(db->resources, local_origin->path); |
4137 } |
4137 } |
4138 // replace LocalResource with origin content |
4138 |
4139 local->origin = NULL; |
4139 // set resource metadata |
4140 char *path = strdup(local->path); |
4140 DavResource *up_res = dav_resource_new(origin->session, local->path); |
4141 // TODO: free stuff before replacing it |
4141 if(!up_res) { |
4142 memcpy(local, local_origin, sizeof(LocalResource)); |
4142 return 1; |
4143 local->path = path; |
4143 } |
4144 |
4144 |
4145 free(local_origin); // only free origin pointer |
4145 sync_set_metadata_from_stat(local, &s); |
|
4146 MetadataHashes hashes; |
|
4147 hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local, TRUE); |
|
4148 if(dav_store(up_res)) { |
|
4149 fprintf(stderr, "Error: cannot store resource metadata\n"); |
|
4150 } |
4146 |
4151 |
4147 // get new etag |
4152 // get new etag |
4148 DavResource *up_res = dav_get(origin->session, local->path, "D:getetag"); |
4153 DavPropName p; |
4149 if(up_res) { |
4154 p.ns = "DAV:"; |
|
4155 p.name = "getetag"; |
|
4156 if(!dav_load_prop(up_res, &p, 1)) { |
4150 (*counter)++; |
4157 (*counter)++; |
4151 |
|
4152 // set metadata |
|
4153 MetadataHashes hashes; |
|
4154 hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local); |
|
4155 if(dav_store(up_res)) { |
|
4156 fprintf(stderr, "Error: cannot store resource metadata\n"); |
|
4157 } |
|
4158 |
4158 |
4159 // everything seems fine, we can update the local resource |
4159 // everything seems fine, we can update the local resource |
4160 char *etag = dav_get_string_property(up_res, "D:getetag"); |
4160 char *etag = dav_get_string_property(up_res, "D:getetag"); |
4161 local_resource_set_etag(local, etag); |
4161 local_resource_set_etag(local, etag); |
4162 |
4162 |
4163 local->last_modified = s.st_mtime; |
4163 local->last_modified = s.st_mtime; |
4164 |
|
4165 dav_resource_free(up_res); |
|
4166 } else { |
4164 } else { |
4167 result = 1; |
4165 result = 1; |
4168 } |
4166 } |
4169 |
4167 |
|
4168 dav_resource_free(up_res); |
4170 return result; |
4169 return result; |
4171 } |
4170 } |
4172 |
4171 |
4173 int sync_delete_remote_resource( |
4172 int sync_delete_remote_resource( |
4174 SyncDirectory *dir, |
4173 SyncDirectory *dir, |
4240 |
4239 |
4241 MetadataHashes sync_set_metadata_properties( |
4240 MetadataHashes sync_set_metadata_properties( |
4242 SyncDirectory *dir, |
4241 SyncDirectory *dir, |
4243 DavSession *sn, |
4242 DavSession *sn, |
4244 DavResource *res, |
4243 DavResource *res, |
4245 LocalResource *local) |
4244 LocalResource *local, |
|
4245 DavBool force) |
4246 { |
4246 { |
|
4247 if(force) { |
|
4248 local->tags_updated = 1; |
|
4249 local->finfo_updated = 1; |
|
4250 local->xattr_updated = 1; |
|
4251 } |
|
4252 |
4247 MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; |
4253 MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; |
4248 if(dir->tagconfig) { |
4254 if(dir->tagconfig) { |
4249 // get local tags |
4255 // get local tags |
4250 DavBool changed = 0; |
4256 DavBool changed = 0; |
4251 char *tags_hash = NULL; |
4257 char *tags_hash = NULL; |
4268 } |
4274 } |
4269 char *remote_hash = create_tags_hash(remote_tags); |
4275 char *remote_hash = create_tags_hash(remote_tags); |
4270 |
4276 |
4271 if(nullstrcmp(remote_hash, local->remote_tags_hash)) { |
4277 if(nullstrcmp(remote_hash, local->remote_tags_hash)) { |
4272 // the tags have changed on the server |
4278 // the tags have changed on the server |
4273 switch(dir->tagconfig->conflict) { |
4279 int conflict_resolution = force ? TAG_NO_CONFLICT : dir->tagconfig->conflict; |
|
4280 switch(conflict_resolution) { |
4274 case TAG_NO_CONFLICT: break; |
4281 case TAG_NO_CONFLICT: break; |
4275 case TAG_KEEP_LOCAL: break; |
4282 case TAG_KEEP_LOCAL: break; |
4276 case TAG_KEEP_REMOTE: { |
4283 case TAG_KEEP_REMOTE: { |
4277 store_tags = FALSE; |
4284 store_tags = FALSE; |
4278 local->tags_updated = FALSE; |
4285 local->tags_updated = FALSE; |
4343 free(local->xattr_hash); |
4350 free(local->xattr_hash); |
4344 local->xattr_hash = NULL; |
4351 local->xattr_hash = NULL; |
4345 } |
4352 } |
4346 } |
4353 } |
4347 } |
4354 } |
|
4355 |
|
4356 local->tags_updated = 0; |
|
4357 |
4348 return hashes; |
4358 return hashes; |
4349 } |
4359 } |
4350 |
4360 |
4351 int sync_update_metadata( |
4361 int sync_update_metadata( |
4352 SyncDirectory *dir, |
4362 SyncDirectory *dir, |
4353 DavSession *sn, |
4363 DavSession *sn, |
4354 DavResource *res, |
4364 DavResource *res, |
4355 LocalResource *local) |
4365 LocalResource *local) |
4356 { |
4366 { |
4357 MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local); |
4367 MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local, FALSE); |
4358 |
4368 |
4359 int err = 0; |
4369 int err = 0; |
4360 if(dav_store(res)) { |
4370 if(dav_store(res)) { |
4361 print_resource_error(sn, local->path); |
4371 print_resource_error(sn, local->path); |
4362 err = 1; |
4372 err = 1; |