1159 } |
1159 } |
1160 } |
1160 } |
1161 |
1161 |
1162 // delete all removed files |
1162 // delete all removed files |
1163 if(ret == 0 && !archive) { |
1163 if(ret == 0 && !archive) { |
|
1164 UcxList *cols = NULL; |
|
1165 |
1164 UcxMapIterator i = ucx_map_iterator(db->resources); |
1166 UcxMapIterator i = ucx_map_iterator(db->resources); |
1165 LocalResource *local; |
1167 LocalResource *local; |
1166 UCX_MAP_FOREACH(key, local, i) { |
1168 UCX_MAP_FOREACH(key, local, i) { |
1167 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
1169 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
1168 if(sync_shutdown) { |
1170 if(sync_shutdown) { |
1169 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1171 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1170 } else if(sync_delete_remote_resource(sn, local, &sync_delete)) { |
1172 } else if(sync_delete_remote_resource(sn, local, &sync_delete, &cols)) { |
1171 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1173 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1172 if(sn->error != DAV_NOT_FOUND) { |
1174 if(sn->error != DAV_NOT_FOUND) { |
1173 print_resource_error(sn, local->path); |
1175 print_resource_error(sn, local->path); |
1174 sync_error++; |
1176 sync_error++; |
1175 break; |
1177 break; |
1176 } |
1178 } |
1177 } |
1179 } |
1178 } |
1180 } |
1179 } |
1181 } |
|
1182 |
|
1183 cols = ucx_list_sort(cols, (cmp_func)resource_pathlen_cmp, NULL); |
|
1184 |
|
1185 UCX_FOREACH(elm, cols) { |
|
1186 local = elm->data; |
|
1187 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
|
1188 if(sync_shutdown) { |
|
1189 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
|
1190 } else if(sync_delete_remote_resource(sn, local, &sync_delete, NULL)) { |
|
1191 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
|
1192 if(sn->error != DAV_NOT_FOUND) { |
|
1193 print_resource_error(sn, local->path); |
|
1194 sync_error++; |
|
1195 break; |
|
1196 } |
|
1197 } |
|
1198 } |
|
1199 } |
|
1200 |
|
1201 ucx_list_free(cols); |
1180 } |
1202 } |
1181 ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free); |
1203 ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free); |
1182 ucx_map_free(db->resources); |
1204 ucx_map_free(db->resources); |
1183 db->resources = lclres; |
1205 db->resources = lclres; |
1184 |
1206 |
1437 dav_resource_free(remote); |
1459 dav_resource_free(remote); |
1438 } |
1460 } |
1439 return ret; |
1461 return ret; |
1440 } |
1462 } |
1441 |
1463 |
|
1464 int resource_pathlen_cmp(LocalResource *res1, LocalResource *res2, void *n) { |
|
1465 size_t s1 = strlen(res1->path); |
|
1466 size_t s2 = strlen(res2->path); |
|
1467 if(s1 < s2) { |
|
1468 return 1; |
|
1469 } else if(s1 > s2) { |
|
1470 return -1; |
|
1471 } else { |
|
1472 return 0; |
|
1473 } |
|
1474 } |
|
1475 |
1442 |
1476 |
1443 int sync_set_status(DavResource *res, char *status) { |
1477 int sync_set_status(DavResource *res, char *status) { |
1444 DavResource *resource = dav_resource_new(res->session, res->path); |
1478 DavResource *resource = dav_resource_new(res->session, res->path); |
1445 dav_set_string_property(resource, "idav:status", status); |
1479 dav_set_string_property(resource, "idav:status", status); |
1446 int ret = dav_store(resource); |
1480 int ret = dav_store(resource); |
1828 } |
1862 } |
1829 |
1863 |
1830 int sync_delete_remote_resource( |
1864 int sync_delete_remote_resource( |
1831 DavSession *sn, |
1865 DavSession *sn, |
1832 LocalResource *local_res, |
1866 LocalResource *local_res, |
1833 int *counter) |
1867 int *counter, |
|
1868 UcxList **cols) |
1834 { |
1869 { |
1835 DavResource *res = dav_get(sn, local_res->path, "D:getetag"); |
1870 DavResource *res = dav_get(sn, local_res->path, "D:getetag"); |
1836 if(!res) { |
1871 if(!res) { |
1837 return sn->error == DAV_NOT_FOUND ? 0 : 1; |
1872 return sn->error == DAV_NOT_FOUND ? 0 : 1; |
1838 } |
1873 } |
1839 |
1874 |
1840 int ret = 0; |
1875 int ret = 0; |
|
1876 sn->error = DAV_OK; |
1841 if(res->iscollection) { |
1877 if(res->iscollection) { |
1842 printf("delete: %s\n", res->path); |
1878 if(cols) { |
1843 if(dav_delete(res)) { |
1879 *cols = ucx_list_append(*cols, local_res); |
1844 ret = 1; |
1880 } else if(!res->children) { |
1845 fprintf(stderr, "Cannot delete resource %s\n", res->path); |
1881 printf("delete: %s\n", res->path); |
|
1882 if(dav_delete(res)) { |
|
1883 ret = 1; |
|
1884 fprintf(stderr, "Cannot delete collection %s\n", res->path); |
|
1885 } else { |
|
1886 (*counter)++; |
|
1887 } |
1846 } |
1888 } |
1847 } else { |
1889 } else { |
1848 char *etag = dav_get_string_property(res, "D:getetag"); |
1890 char *etag = dav_get_string_property(res, "D:getetag"); |
1849 if(etag) { |
1891 if(etag) { |
1850 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { |
1892 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { |