956 int *err) |
956 int *err) |
957 { |
957 { |
958 UcxList *updates = NULL; |
958 UcxList *updates = NULL; |
959 |
959 |
960 size_t local_numparts = local ? local->numparts : 0; |
960 size_t local_numparts = local ? local->numparts : 0; |
|
961 fseeko(out, 0, SEEK_END); |
|
962 off_t end = ftello(out); |
961 |
963 |
962 int error = 0; |
964 int error = 0; |
963 |
965 |
964 UcxBuffer *buf = ucx_buffer_new(NULL, blocksize, 0); |
966 UcxBuffer *buf = ucx_buffer_new(NULL, blocksize, 0); |
965 |
967 |
994 error = 1; |
996 error = 1; |
995 fprintf(stderr, "Error: part number too high\n"); |
997 fprintf(stderr, "Error: part number too high\n"); |
996 break; |
998 break; |
997 } |
999 } |
998 |
1000 |
|
1001 int64_t block_end = 0; |
999 if(download_part) { |
1002 if(download_part) { |
1000 if(fseeko(out, offset, SEEK_SET)) { |
1003 if(fseeko(out, offset, SEEK_SET)) { |
1001 error = 1; |
1004 error = 1; |
1002 fprintf(stderr, "Error: fseek failed: %s\n", strerror(errno)); |
1005 fprintf(stderr, "Error: fseek failed: %s\n", strerror(errno)); |
1003 break; |
1006 break; |
1007 if(dav_get_content(part, buf,(dav_write_func)ucx_buffer_write)) { |
1010 if(dav_get_content(part, buf,(dav_write_func)ucx_buffer_write)) { |
1008 fprintf(stderr, "Error: cannot download part: %s\n", part->name); |
1011 fprintf(stderr, "Error: cannot download part: %s\n", part->name); |
1009 error = 1; |
1012 error = 1; |
1010 break; |
1013 break; |
1011 } |
1014 } |
1012 printf("offset: %lu length: %lu\n", offset, (uint64_t)buf->size); |
|
1013 if(fwrite(buf->space, 1, buf->size, out) == 0) { |
1015 if(fwrite(buf->space, 1, buf->size, out) == 0) { |
1014 perror("write"); |
1016 perror("write"); |
1015 error = 1; |
1017 error = 1; |
1016 break; |
1018 break; |
1017 } |
1019 } |
1019 FilePart *update = calloc(1, sizeof(FilePart)); |
1021 FilePart *update = calloc(1, sizeof(FilePart)); |
1020 update->block = partnum; |
1022 update->block = partnum; |
1021 update->etag = etag ? strdup(etag) : NULL; |
1023 update->etag = etag ? strdup(etag) : NULL; |
1022 update->hash = dav_create_hash(buf->space, buf->size); |
1024 update->hash = dav_create_hash(buf->space, buf->size); |
1023 updates = ucx_list_append(updates, update); |
1025 updates = ucx_list_append(updates, update); |
|
1026 |
|
1027 block_end = offset+buf->size; |
|
1028 } else { |
|
1029 if(offset+blocksize > end) { |
|
1030 // if we don't download the block, we don't know the size |
|
1031 // but it can't be bigger than the file |
|
1032 block_end = end; |
|
1033 } else { |
|
1034 block_end = offset+blocksize; |
|
1035 } |
1024 } |
1036 } |
1025 |
1037 |
1026 |
1038 if(block_end > maxsize) { |
|
1039 maxsize = block_end; |
|
1040 } |
1027 |
1041 |
1028 i++; |
1042 i++; |
1029 } // else: res is not a regular file part |
1043 } // else: res is not a regular file part |
1030 part = part->next; |
1044 part = part->next; |
1031 } |
1045 } |