1582 UcxList *elm = ls_new; |
1582 UcxList *elm = ls_new; |
1583 while(elm) { |
1583 while(elm) { |
1584 LocalResource *local = elm->data; |
1584 LocalResource *local = elm->data; |
1585 UcxList *prev = elm->prev; |
1585 UcxList *prev = elm->prev; |
1586 UcxList *next = elm->next; |
1586 UcxList *next = elm->next; |
|
1587 if(local->isdirectory) { |
|
1588 elm = elm->next; |
|
1589 continue; |
|
1590 } |
|
1591 |
1587 char *local_path = util_concat_path(dir->path, local->path); |
1592 char *local_path = util_concat_path(dir->path, local->path); |
1588 char *hash = util_file_hash(local_path); |
1593 char *hash = util_file_hash(local_path); |
|
1594 local->hash = hash; |
1589 // check if a file with this hash already exists |
1595 // check if a file with this hash already exists |
1590 LocalResource *origin = ucx_map_cstr_get(db_hashes, hash); |
1596 LocalResource *origin = ucx_map_cstr_get(db_hashes, hash); |
1591 if(origin) { |
1597 if(origin) { |
1592 local->origin = strdup(origin->path); |
1598 local->origin = strdup(origin->path); |
1593 // the file is a copied/moved file |
1599 // the file is a copied/moved file |
1720 dav_resource_free(res); |
1725 dav_resource_free(res); |
1721 |
1726 |
1722 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); |
1727 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path); |
1723 ucx_map_cstr_put(db->resources, local_res->path, local_res); |
1728 ucx_map_cstr_put(db->resources, local_res->path, local_res); |
1724 //if(dbres) local_resource_free(dbres); |
1729 //if(dbres) local_resource_free(dbres); |
|
1730 } |
|
1731 |
|
1732 DavBool copy = TRUE; |
|
1733 for(UcxList *elm=ls_copy;elm && !sync_shutdown;elm=elm->next) { |
|
1734 LocalResource *local = elm->data; |
|
1735 DavResource *res = dav_resource_new(sn, local->origin); |
|
1736 int err = 0; |
|
1737 if(copy) { |
|
1738 printf("copy: %s -> %s\n", local->origin, local->path); |
|
1739 err = dav_copy_o(res, local->path, FALSE); |
|
1740 |
|
1741 if(!elm->next) { |
|
1742 // finished copy, begin move |
|
1743 elm->next = ls_move; |
|
1744 copy = FALSE; |
|
1745 } |
|
1746 } else { |
|
1747 printf("move: %s -> %s\n", local->origin, local->path); |
|
1748 err = dav_move_o(res, local->path, FALSE); |
|
1749 } |
|
1750 |
|
1751 if(err) { |
|
1752 if(sn->error == DAV_PRECONDITION_FAILED) { |
|
1753 printf("conflict: %s\n", local->path); |
|
1754 local->last_modified = 0; |
|
1755 local->skipped = TRUE; |
|
1756 sync_skipped++; |
|
1757 } else { |
|
1758 sync_error++; |
|
1759 print_resource_error(sn, res->path); |
|
1760 ret = -1; |
|
1761 error = 1; |
|
1762 } |
|
1763 } |
|
1764 |
|
1765 dav_resource_free(res); |
|
1766 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path); |
|
1767 ucx_map_cstr_put(db->resources, local->path, local); |
1725 } |
1768 } |
1726 |
1769 |
1727 // metadata updates |
1770 // metadata updates |
1728 for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) { |
1771 for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) { |
1729 LocalResource *local_res = elm->data; |
1772 LocalResource *local_res = elm->data; |