dav/sync.c

changeset 523
923a4528a2ae
parent 522
46f96dcd6eab
child 524
d53fd1006485
equal deleted inserted replaced
522:46f96dcd6eab 523:923a4528a2ae
1234 svrres, 1234 svrres,
1235 restore_removed, 1235 restore_removed,
1236 restore_modified); 1236 restore_modified);
1237 if(is_changed) { 1237 if(is_changed) {
1238 ls_put = ucx_list_append(ls_put, local_res); 1238 ls_put = ucx_list_append(ls_put, local_res);
1239 } else if(local_res->tags_updated) { 1239 } else if(local_res->metadata_updated) {
1240 ls_update = ucx_list_append(ls_update, local_res); 1240 ls_update = ucx_list_append(ls_update, local_res);
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 // find all deleted files and cleanup the database 1244 // find all deleted files and cleanup the database
1310 error = 1; 1310 error = 1;
1311 abort = 1; 1311 abort = 1;
1312 } 1312 }
1313 1313
1314 if(dir->tagconfig && local_res->tags_updated && !abort) { 1314 if(dir->tagconfig && local_res->tags_updated && !abort) {
1315 sync_update_tags(dir, sn, res, local_res); 1315 sync_update_metadata(dir, sn, res, local_res);
1316 } 1316 }
1317 } else if(sn->error != DAV_OK) { 1317 } else if(sn->error != DAV_OK) {
1318 // dav_exists() failed 1318 // dav_exists() failed
1319 print_resource_error(sn, local_res->path); 1319 print_resource_error(sn, local_res->path);
1320 ret = -1; 1320 ret = -1;
1348 for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) { 1348 for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) {
1349 LocalResource *local_res = elm->data; 1349 LocalResource *local_res = elm->data;
1350 1350
1351 DavResource *res = dav_resource_new(sn, local_res->path); 1351 DavResource *res = dav_resource_new(sn, local_res->path);
1352 1352
1353 if(dir->tagconfig && local_res->tags_updated) { 1353 if(local_res->metadata_updated) {
1354 sync_update_tags(dir, sn, res, local_res); 1354 if(!sync_update_metadata(dir, sn, res, local_res)) {
1355 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
1356 ucx_map_cstr_put(db->resources, local_res->path, local_res);
1357 }
1355 } 1358 }
1356 } 1359 }
1357 1360
1358 // delete all removed files 1361 // delete all removed files
1359 UcxList *cols = NULL; 1362 UcxList *cols = NULL;
1767 res->tags_updated = 1; 1770 res->tags_updated = 1;
1768 } 1771 }
1769 } else if(db_res->tags_hash) { 1772 } else if(db_res->tags_hash) {
1770 res->tags_updated = 1; // tags removed 1773 res->tags_updated = 1; // tags removed
1771 } 1774 }
1775 res->metadata_updated = res->tags_updated;
1776 }
1777
1778 if(dir->metadata & FINFO_MODE == FINFO_MODE) {
1779 if(db_res->mode != res->mode) {
1780 res->finfo_updated = 1;
1781 res->metadata_updated = 1;
1782 }
1783 }
1784 if(dir->metadata & FINFO_OWNER == FINFO_OWNER) {
1785 if(db_res->uid != res->uid || db_res->gid != res->gid) {
1786 res->finfo_updated = 1;
1787 res->metadata_updated = 1;
1788 }
1789 }
1790
1791 if(dir->metadata & FINFO_XATTR == FINFO_XATTR) {
1792 char *path = util_concat_path(dir->path, db_res->path);
1793 XAttributes *xattr = file_get_attributes(path);
1794 if((db_res->xattr_hash && !xattr) ||
1795 (!db_res->xattr_hash && xattr) ||
1796 strcmp(xattr->hash, db_res->xattr_hash))
1797 {
1798 res->metadata_updated = 1;
1799 res->xattr_updated = 1;
1800 res->xattr = xattr;
1801 } else if(xattr) {
1802 xattributes_free(xattr);
1803 }
1772 } 1804 }
1773 1805
1774 if(db_res->last_modified == res->last_modified && db_res->size == res->size) { 1806 if(db_res->last_modified == res->last_modified && db_res->size == res->size) {
1775 return 0; 1807 return 0;
1776 } 1808 }
2440 dav_resource_free(res); 2472 dav_resource_free(res);
2441 2473
2442 return ret; 2474 return ret;
2443 } 2475 }
2444 2476
2445 int sync_update_tags(SyncDirectory *dir, DavSession *sn, DavResource *res, LocalResource *local) { 2477 int sync_update_metadata(SyncDirectory *dir, DavSession *sn, DavResource *res, LocalResource *local) {
2446 if(!dir->tagconfig || !local->tags_updated) { 2478 if(dir->tagconfig && local->tags_updated) {
2447 return 0; 2479 // get local tags
2448 } 2480 UcxList *tags = sync_get_file_tags(dir, local, NULL);
2449 2481
2450 // get local tags 2482 DavXmlNode *prop = create_xml_taglist(tags);
2451 UcxList *tags = sync_get_file_tags(dir, local, NULL); 2483 if(prop) {
2452 2484 dav_set_property_ns(res, DAV_NS, "tags", prop);
2453 DavXmlNode *prop = create_xml_taglist(tags); 2485 } else {
2454 if(prop) { 2486 dav_remove_property_ns(res, DAV_NS, "tags");
2455 dav_set_property_ns(res, DAV_NS, "tags", prop); 2487 }
2456 } else { 2488 }
2457 dav_remove_property_ns(res, DAV_NS, "tags"); 2489
2458 } 2490 if(local->finfo_updated) {
2459 2491 struct stat s;
2492 s.st_mode = local->mode;
2493 s.st_mtime = local->last_modified;
2494 s.st_uid = local->uid;
2495 s.st_gid = local->gid;
2496 resource_set_finfo_s(&s, res, dir->metadata);
2497 }
2498
2499 if(local->xattr_updated) {
2500 if(local->xattr) {
2501 resource_set_xattr(res, local->xattr);
2502 } else {
2503 dav_remove_property(res, "idav:xattributes");
2504 }
2505 }
2506
2507 int err = 0;
2460 printf("update: %s\n", local->path); 2508 printf("update: %s\n", local->path);
2461 if(dav_store(res)) { 2509 if(dav_store(res)) {
2462 print_resource_error(sn, local->path); 2510 print_resource_error(sn, local->path);
2511 err = 1;
2463 } else { 2512 } else {
2464 UcxBuffer *tag_data = local->cached_tags; 2513 if(dir->tagconfig && local->tags_updated) {
2465 if(local->tags_hash) { 2514 UcxBuffer *tag_data = local->cached_tags;
2466 free(local->tags_hash); 2515 if(local->tags_hash) {
2467 local->tags_hash = NULL; 2516 free(local->tags_hash);
2468 } 2517 local->tags_hash = NULL;
2469 if(tag_data) { 2518 }
2470 char *hash = dav_create_hash(tag_data->space, tag_data->size); 2519 if(tag_data) {
2471 local->tags_hash = hash; 2520 char *hash = dav_create_hash(tag_data->space, tag_data->size);
2472 } 2521 local->tags_hash = hash;
2473 local->tags_updated = FALSE; 2522 }
2474 } 2523 local->tags_updated = FALSE;
2475 2524 }
2525 if(local->xattr) {
2526 local->xattr_hash = strdup(local->xattr->hash);
2527 }
2528 }
2529
2476 // TODO: free stuff 2530 // TODO: free stuff
2477 return 0; 2531 return err;
2478 } 2532 }
2479
2480 2533
2481 void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db) { 2534 void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db) {
2482 char **dc = calloc(sizeof(void*), db->conflict->count); 2535 char **dc = calloc(sizeof(void*), db->conflict->count);
2483 int numdc = 0; 2536 int numdc = 0;
2484 2537

mercurial