1195 } |
1195 } |
1196 } |
1196 } |
1197 |
1197 |
1198 // delete all removed files |
1198 // delete all removed files |
1199 if(ret == 0 && !archive) { |
1199 if(ret == 0 && !archive) { |
|
1200 UcxList *cols = NULL; |
|
1201 |
1200 UcxMapIterator i = ucx_map_iterator(db->resources); |
1202 UcxMapIterator i = ucx_map_iterator(db->resources); |
1201 LocalResource *local; |
1203 LocalResource *local; |
1202 UCX_MAP_FOREACH(key, local, i) { |
1204 UCX_MAP_FOREACH(key, local, i) { |
1203 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
1205 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
1204 if(sync_shutdown) { |
1206 if(sync_shutdown) { |
1205 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1207 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1206 } else if(sync_delete_remote_resource(sn, local, &sync_delete)) { |
1208 } else if(sync_delete_remote_resource(sn, local, &sync_delete, &cols)) { |
1207 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1209 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
1208 if(sn->error != DAV_NOT_FOUND) { |
1210 if(sn->error != DAV_NOT_FOUND) { |
1209 print_resource_error(sn, local->path); |
1211 print_resource_error(sn, local->path); |
1210 sync_error++; |
1212 sync_error++; |
1211 break; |
1213 break; |
1212 } |
1214 } |
1213 } |
1215 } |
1214 } |
1216 } |
1215 } |
1217 } |
|
1218 |
|
1219 cols = ucx_list_sort(cols, (cmp_func)resource_pathlen_cmp, NULL); |
|
1220 |
|
1221 UCX_FOREACH(elm, cols) { |
|
1222 local = elm->data; |
|
1223 if (!local->keep && !res_matches_filter(dir, local->path+1)) { |
|
1224 if(sync_shutdown) { |
|
1225 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
|
1226 } else if(sync_delete_remote_resource(sn, local, &sync_delete, NULL)) { |
|
1227 ucx_map_cstr_put(lclres, local->path, local_resource_copy(local)); |
|
1228 if(sn->error != DAV_NOT_FOUND) { |
|
1229 print_resource_error(sn, local->path); |
|
1230 sync_error++; |
|
1231 break; |
|
1232 } |
|
1233 } |
|
1234 } |
|
1235 } |
|
1236 |
|
1237 ucx_list_free(cols); |
1216 } |
1238 } |
1217 ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free); |
1239 ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free); |
1218 ucx_map_free(db->resources); |
1240 ucx_map_free(db->resources); |
1219 db->resources = lclres; |
1241 db->resources = lclres; |
1220 |
1242 |
1498 dav_resource_free(remote); |
1520 dav_resource_free(remote); |
1499 } |
1521 } |
1500 return ret; |
1522 return ret; |
1501 } |
1523 } |
1502 |
1524 |
|
1525 int resource_pathlen_cmp(LocalResource *res1, LocalResource *res2, void *n) { |
|
1526 size_t s1 = strlen(res1->path); |
|
1527 size_t s2 = strlen(res2->path); |
|
1528 if(s1 < s2) { |
|
1529 return 1; |
|
1530 } else if(s1 > s2) { |
|
1531 return -1; |
|
1532 } else { |
|
1533 return 0; |
|
1534 } |
|
1535 } |
|
1536 |
1503 |
1537 |
1504 int sync_set_status(DavResource *res, char *status) { |
1538 int sync_set_status(DavResource *res, char *status) { |
1505 DavResource *resource = dav_resource_new(res->session, res->path); |
1539 DavResource *resource = dav_resource_new(res->session, res->path); |
1506 dav_set_string_property(resource, "idav:status", status); |
1540 dav_set_string_property(resource, "idav:status", status); |
1507 int ret = dav_store(resource); |
1541 int ret = dav_store(resource); |
1889 } |
1923 } |
1890 |
1924 |
1891 int sync_delete_remote_resource( |
1925 int sync_delete_remote_resource( |
1892 DavSession *sn, |
1926 DavSession *sn, |
1893 LocalResource *local_res, |
1927 LocalResource *local_res, |
1894 int *counter) |
1928 int *counter, |
|
1929 UcxList **cols) |
1895 { |
1930 { |
1896 DavResource *res = dav_get(sn, local_res->path, "D:getetag"); |
1931 DavResource *res = dav_get(sn, local_res->path, "D:getetag"); |
1897 if(!res) { |
1932 if(!res) { |
1898 return sn->error == DAV_NOT_FOUND ? 0 : 1; |
1933 return sn->error == DAV_NOT_FOUND ? 0 : 1; |
1899 } |
1934 } |
1900 |
1935 |
1901 int ret = 0; |
1936 int ret = 0; |
|
1937 sn->error = DAV_OK; |
1902 if(res->iscollection) { |
1938 if(res->iscollection) { |
1903 printf("delete: %s\n", res->path); |
1939 if(cols) { |
1904 if(dav_delete(res)) { |
1940 *cols = ucx_list_append(*cols, local_res); |
1905 ret = 1; |
1941 } else if(!res->children) { |
1906 fprintf(stderr, "Cannot delete resource %s\n", res->path); |
1942 printf("delete: %s\n", res->path); |
|
1943 if(dav_delete(res)) { |
|
1944 ret = 1; |
|
1945 fprintf(stderr, "Cannot delete collection %s\n", res->path); |
|
1946 } else { |
|
1947 (*counter)++; |
|
1948 } |
1907 } |
1949 } |
1908 } else { |
1950 } else { |
1909 char *etag = dav_get_string_property(res, "D:getetag"); |
1951 char *etag = dav_get_string_property(res, "D:getetag"); |
1910 if(etag) { |
1952 if(etag) { |
1911 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { |
1953 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') { |