dav/sync.c

changeset 546
33e312dd851d
parent 545
268157722a0e
child 547
4a249c645ae4
equal deleted inserted replaced
545:268157722a0e 546:33e312dd851d
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 }
1036 *err = 1; 1050 *err = 1;
1037 ucx_list_free_content(updates, (ucx_destructor)filepart_free); 1051 ucx_list_free_content(updates, (ucx_destructor)filepart_free);
1038 return NULL; 1052 return NULL;
1039 } 1053 }
1040 1054
1055 if(maxsize < end) {
1056 *truncate_file = maxsize;
1057 } else {
1058 *truncate_file = -1;
1059 }
1060
1041 *err = 0; 1061 *err = 0;
1042 *blockcount = i; 1062 *blockcount = i;
1043 *truncate_file = maxsize;
1044 return updates; 1063 return updates;
1045 } 1064 }
1046 1065
1047 1066
1048 1067

mercurial