3311 int sync_store_tags(SyncDirectory *dir, const char *path, LocalResource *local, DavResource *res) { |
3311 int sync_store_tags(SyncDirectory *dir, const char *path, LocalResource *local, DavResource *res) { |
3312 if(!dir->tagconfig) { |
3312 if(!dir->tagconfig) { |
3313 return 0; |
3313 return 0; |
3314 } |
3314 } |
3315 |
3315 |
|
3316 char *remote_hash = NULL; |
3316 UcxList *tags = NULL; |
3317 UcxList *tags = NULL; |
3317 if(dir->tagconfig) { |
3318 if(dir->tagconfig) { |
3318 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
3319 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
3319 if(tagsprop) { |
3320 if(tagsprop) { |
3320 tags = parse_dav_xml_taglist(tagsprop); |
3321 tags = parse_dav_xml_taglist(tagsprop); |
3321 |
3322 remote_hash = create_tags_hash(tags); |
3322 } |
3323 } |
3323 } |
3324 } |
3324 |
3325 |
3325 DavBool store_tags = FALSE; |
3326 DavBool store_tags = FALSE; |
3326 DavBool tags_changed = FALSE; |
3327 DavBool tags_changed = FALSE; |
4233 DavSession *sn, |
4240 DavSession *sn, |
4234 DavResource *res, |
4241 DavResource *res, |
4235 LocalResource *local) |
4242 LocalResource *local) |
4236 { |
4243 { |
4237 MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; |
4244 MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; |
4238 if(dir->tagconfig) { |
4245 if(dir->tagconfig) { |
4239 // get local tags |
4246 // get local tags |
4240 DavBool changed = 0; |
4247 DavBool changed = 0; |
4241 char *tags_hash = NULL; |
4248 char *tags_hash = NULL; |
4242 UcxList *tags = sync_get_file_tags(dir, local, &changed, &tags_hash); |
4249 UcxList *tags = sync_get_file_tags(dir, local, &changed, &tags_hash); |
4243 if(changed || local->tags_updated) { |
4250 char *new_remote_hash = nullstrdup(tags_hash); |
4244 hashes.tags = tags_hash; |
4251 if(changed || local->tags_updated) { |
4245 hashes.update_tags = 1; |
4252 DavBool store_tags = TRUE; |
4246 |
4253 |
4247 DavBool store_tags = TRUE; |
|
4248 // get remote tags |
4254 // get remote tags |
|
4255 DavPropName p; |
|
4256 p.ns = DAV_PROPS_NS; |
|
4257 p.name = "tags"; |
|
4258 if(dav_load_prop(res, &p, 1) && sn->error != DAV_NOT_FOUND) { |
|
4259 print_resource_error(sn, res->path); |
|
4260 } |
4249 UcxList *remote_tags = NULL; |
4261 UcxList *remote_tags = NULL; |
4250 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
4262 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
4251 if(tagsprop) { |
4263 if(tagsprop) { |
4252 remote_tags = parse_dav_xml_taglist(tagsprop); |
4264 remote_tags = parse_dav_xml_taglist(tagsprop); |
4253 } |
4265 } |
4254 char *remote_hash = create_tags_hash(remote_tags); |
4266 char *remote_hash = create_tags_hash(remote_tags); |
|
4267 |
4255 if(nullstrcmp(remote_hash, local->remote_tags_hash)) { |
4268 if(nullstrcmp(remote_hash, local->remote_tags_hash)) { |
4256 // the tags have changed on the server |
4269 // the tags have changed on the server |
4257 switch(dir->tagconfig->conflict) { |
4270 switch(dir->tagconfig->conflict) { |
4258 case TAG_NO_CONFLICT: break; |
4271 case TAG_NO_CONFLICT: break; |
4259 case TAG_KEEP_LOCAL: break; |
4272 case TAG_KEEP_LOCAL: break; |
4264 } |
4277 } |
4265 case TAG_MERGE: { |
4278 case TAG_MERGE: { |
4266 UcxList *new_tags = merge_tags(tags, remote_tags); |
4279 UcxList *new_tags = merge_tags(tags, remote_tags); |
4267 free_taglist(tags); |
4280 free_taglist(tags); |
4268 tags = new_tags; |
4281 tags = new_tags; |
|
4282 |
|
4283 nullfree(tags_hash); |
|
4284 nullfree(new_remote_hash); |
|
4285 tags_hash = create_tags_hash(tags); |
|
4286 new_remote_hash = nullstrdup(tags_hash); |
|
4287 |
4269 break; |
4288 break; |
4270 } |
4289 } |
4271 } |
4290 } |
4272 } |
4291 } |
|
4292 nullfree(remote_hash); |
4273 |
4293 |
4274 if(dir->tagconfig->local_format == TAG_FORMAT_CSV) { |
4294 if(dir->tagconfig->local_format == TAG_FORMAT_CSV) { |
4275 // csv tag lists don't have colors, so we have to add |
4295 // csv tag lists don't have colors, so we have to add |
4276 // the colors from the remote tag list |
4296 // the colors from the remote tag list |
4277 add_tag_colors(tags, remote_tags); |
4297 add_tag_colors(tags, remote_tags); |
4282 DavXmlNode *tagprop = create_xml_taglist(tags); |
4302 DavXmlNode *tagprop = create_xml_taglist(tags); |
4283 dav_set_property_ns(res, DAV_PROPS_NS, "tags", tagprop); |
4303 dav_set_property_ns(res, DAV_PROPS_NS, "tags", tagprop); |
4284 } else { |
4304 } else { |
4285 dav_remove_property_ns(res, DAV_PROPS_NS, "tags"); |
4305 dav_remove_property_ns(res, DAV_PROPS_NS, "tags"); |
4286 } |
4306 } |
|
4307 |
|
4308 hashes.tags = tags_hash; |
|
4309 hashes.update_tags = 1; |
|
4310 hashes.tags_remote = new_remote_hash; |
|
4311 hashes.update_tags_remote = 1; |
4287 } |
4312 } |
4288 |
4313 |
4289 free_taglist(remote_tags); |
4314 free_taglist(remote_tags); |
4290 } else { |
4315 } else { |
4291 if(tags_hash) { |
4316 if(tags_hash) { |