550 locked = TRUE; |
550 locked = TRUE; |
551 locktokenfile = create_locktoken_file(dir->name, lock->token); |
551 locktokenfile = create_locktoken_file(dir->name, lock->token); |
552 } |
552 } |
553 |
553 |
554 int ret = 0; |
554 int ret = 0; |
555 DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,`idav:content-hash` from / with depth = infinity"); |
555 DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,idav:link,`idav:content-hash` from / with depth = infinity"); |
556 if(!ls) { |
556 if(!ls) { |
557 print_resource_error(sn, "/"); |
557 print_resource_error(sn, "/"); |
558 if(locked) { |
558 if(locked) { |
559 if(dav_unlock(root)) { |
559 if(dav_unlock(root)) { |
560 print_resource_error(sn, "/"); |
560 print_resource_error(sn, "/"); |
1266 int *counter) |
1270 int *counter) |
1267 { |
1271 { |
1268 LocalResource *local = ucx_map_cstr_get(db->resources, path); |
1272 LocalResource *local = ucx_map_cstr_get(db->resources, path); |
1269 char *local_path = create_local_path(dir, path); |
1273 char *local_path = create_local_path(dir, path); |
1270 |
1274 |
|
1275 char *link = dav_get_string_property_ns(res, DAV_NS, "link"); |
|
1276 |
1271 char *etag = dav_get_string_property(res, "D:getetag"); |
1277 char *etag = dav_get_string_property(res, "D:getetag"); |
1272 SYS_STAT s; |
1278 SYS_STAT s; |
1273 memset(&s, 0, sizeof(SYS_STAT)); |
1279 memset(&s, 0, sizeof(SYS_STAT)); |
1274 |
1280 |
1275 char *blocksize_str = dav_get_string_property_ns(res, DAV_NS, "split"); |
1281 char *blocksize_str = dav_get_string_property_ns(res, DAV_NS, "split"); |
1283 issplit = TRUE; |
1289 issplit = TRUE; |
1284 } |
1290 } |
1285 UcxList *part_updates = NULL; |
1291 UcxList *part_updates = NULL; |
1286 uint64_t blockcount = 0; |
1292 uint64_t blockcount = 0; |
1287 char *content_hash = NULL; |
1293 char *content_hash = NULL; |
1288 |
1294 |
1289 if(res->iscollection && !issplit) { |
1295 if(res->iscollection && !issplit) { |
1290 // why are we here? |
1296 // why are we here? |
1291 return 0; |
1297 return 0; |
1292 } |
1298 } |
1293 |
1299 |
1294 int ret = 0; |
1300 int ret = 0; |
1295 |
1301 |
1296 char *tmp_path = NULL; |
1302 char *tmp_path = NULL; |
1297 FILE *out = NULL; |
1303 FILE *out = NULL; |
1298 if(!issplit) { |
1304 if(!link) { |
1299 tmp_path = create_tmp_download_path(local_path); |
1305 if(!issplit) { |
1300 if(!tmp_path) { |
1306 tmp_path = create_tmp_download_path(local_path); |
1301 fprintf(stderr, "Cannot create tmp path for %s\n", local_path); |
1307 if(!tmp_path) { |
|
1308 fprintf(stderr, "Cannot create tmp path for %s\n", local_path); |
|
1309 free(local_path); |
|
1310 return -1; |
|
1311 } |
|
1312 out = sys_fopen(tmp_path , "wb"); |
|
1313 } else { |
|
1314 out = sys_fopen(local_path, "r+b"); |
|
1315 if(!out && errno == ENOENT) { |
|
1316 out = sys_fopen(local_path, "wb"); |
|
1317 } |
|
1318 } |
|
1319 if(!out) { |
|
1320 fprintf(stderr, "Cannot open output file: %s\n", local_path); |
1302 free(local_path); |
1321 free(local_path); |
|
1322 if(tmp_path) { |
|
1323 free(tmp_path); |
|
1324 } |
1303 return -1; |
1325 return -1; |
1304 } |
1326 } |
1305 out = sys_fopen(tmp_path , "wb"); |
1327 } |
|
1328 |
|
1329 int64_t truncate_file = -1; |
|
1330 if(!link) { |
|
1331 printf("get: %s\n", path); |
|
1332 if(issplit) { |
|
1333 part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret); |
|
1334 } else { |
|
1335 ret = dav_get_content(res, out, (dav_write_func)fwrite); |
|
1336 } |
|
1337 fclose(out); |
1306 } else { |
1338 } else { |
1307 out = sys_fopen(local_path, "r+b"); |
1339 printf("link: %s -> %s\n", path, link); |
1308 if(!out && errno == ENOENT) { |
1340 if(sys_symlink(link, local_path)) { |
1309 out = sys_fopen(local_path, "wb"); |
1341 perror("symlink"); |
1310 } |
1342 ret = 1; |
1311 } |
1343 } |
1312 if(!out) { |
1344 } |
1313 fprintf(stderr, "Cannot open output file: %s\n", local_path); |
|
1314 free(local_path); |
|
1315 if(tmp_path) { |
|
1316 free(tmp_path); |
|
1317 } |
|
1318 return -1; |
|
1319 } |
|
1320 |
|
1321 int64_t truncate_file = -1; |
|
1322 printf("get: %s\n", path); |
|
1323 if(issplit) { |
|
1324 part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret); |
|
1325 } else { |
|
1326 ret = dav_get_content(res, out, (dav_write_func)fwrite); |
|
1327 } |
|
1328 fclose(out); |
|
1329 |
1345 |
1330 if(issplit || dir->hashing) { |
1346 if(issplit || dir->hashing) { |
1331 if(truncate_file >= 0) { |
1347 if(truncate_file >= 0) { |
1332 // only true if issplit is true |
1348 // only true if issplit is true |
1333 if(truncate(local_path, truncate_file)) { |
1349 if(truncate(local_path, truncate_file)) { |