dav/sync.c

changeset 557
90ad7324bbbc
parent 556
1a58014260e0
child 558
1a9e6a5c1e79
equal deleted inserted replaced
556:1a58014260e0 557:90ad7324bbbc
97 } 97 }
98 if(!s1 && !s2) { 98 if(!s1 && !s2) {
99 return 0; 99 return 0;
100 } 100 }
101 return strcmp(s1, s2); 101 return strcmp(s1, s2);
102 }
103
104 static void nullfree(void *p) {
105 if(p) {
106 free(p);
107 }
102 } 108 }
103 109
104 int main(int argc, char **argv) { 110 int main(int argc, char **argv) {
105 if(argc < 2) { 111 if(argc < 2) {
106 fprintf(stderr, "Missing command\n"); 112 fprintf(stderr, "Missing command\n");
1711 } else { 1717 } else {
1712 int changed = remote_resource_is_changed(sn, dir, db, res, local_res); 1718 int changed = remote_resource_is_changed(sn, dir, db, res, local_res);
1713 if(cdt && changed) { 1719 if(cdt && changed) {
1714 printf("conflict: %s\n", local_res->path); 1720 printf("conflict: %s\n", local_res->path);
1715 local_res->last_modified = 0; 1721 local_res->last_modified = 0;
1722 nullfree(local_res->etag);
1723 local_res->etag = NULL;
1724 nullfree(local_res->hash);
1725 local_res->hash = NULL;
1716 local_res->skipped = TRUE; 1726 local_res->skipped = TRUE;
1717 sync_skipped++; 1727 sync_skipped++;
1718 } else { 1728 } else {
1719 printf("put: %s\n", local_res->path); 1729 printf("put: %s\n", local_res->path);
1720 if(sync_put_resource(dir, res, local_res, &sync_success)) { 1730 if(sync_put_resource(dir, res, local_res, &sync_success)) {
1742 1752
1743 int err = 0; 1753 int err = 0;
1744 DavResource *res = dav_resource_new(sn, local->path); 1754 DavResource *res = dav_resource_new(sn, local->path);
1745 if(dav_exists(res)) { 1755 if(dav_exists(res)) {
1746 printf("conflict: %s\n", local->path); 1756 printf("conflict: %s\n", local->path);
1757 local->last_modified = 0;
1758 nullfree(local->etag);
1759 local->etag = NULL;
1760 nullfree(local->hash);
1761 local->hash = NULL;
1762 local->skipped = TRUE;
1747 sync_skipped++; 1763 sync_skipped++;
1748 } else { 1764 } else {
1749 DavResource *origin_res = dav_resource_new(sn, local->origin->path); 1765 DavResource *origin_res = dav_resource_new(sn, local->origin->path);
1750 int origin_changed = remote_resource_is_changed( 1766 int origin_changed = remote_resource_is_changed(
1751 sn, 1767 sn,
2376 2392
2377 int ret = 0; 2393 int ret = 0;
2378 if(err == 0) { 2394 if(err == 0) {
2379 char *etag = dav_get_string_property(remote, "D:getetag"); 2395 char *etag = dav_get_string_property(remote, "D:getetag");
2380 char *hash = sync_get_content_hash(remote); 2396 char *hash = sync_get_content_hash(remote);
2381 if(hash || res->hash) { 2397 if(hash && res->hash) {
2382 if(!nullstrcmp(hash, res->hash)) { 2398 if(!strcmp(hash, res->hash)) {
2383 ret = 1; 2399 ret = 1;
2384 } 2400 }
2385 } else if(!res->etag) { 2401 } else if(!res->etag) {
2386 // the resource is on the server and the client has no etag 2402 // the resource is on the server and the client has no etag
2387 ret = 1; 2403 ret = 1;

mercurial