# HG changeset patch # User Olaf Wintermann # Date 1553799910 -3600 # Node ID 33e312dd851dabe72a2362e03ecaf3f601d9b1e9 # Parent 268157722a0e1adc71588a35272119def633dd4d truncate splitted file to correct size on pull diff -r 268157722a0e -r 33e312dd851d dav/sync.c --- a/dav/sync.c Thu Mar 28 18:23:22 2019 +0100 +++ b/dav/sync.c Thu Mar 28 20:05:10 2019 +0100 @@ -958,6 +958,8 @@ UcxList *updates = NULL; size_t local_numparts = local ? local->numparts : 0; + fseeko(out, 0, SEEK_END); + off_t end = ftello(out); int error = 0; @@ -996,6 +998,7 @@ break; } + int64_t block_end = 0; if(download_part) { if(fseeko(out, offset, SEEK_SET)) { error = 1; @@ -1009,7 +1012,6 @@ error = 1; break; } - printf("offset: %lu length: %lu\n", offset, (uint64_t)buf->size); if(fwrite(buf->space, 1, buf->size, out) == 0) { perror("write"); error = 1; @@ -1021,9 +1023,21 @@ update->etag = etag ? strdup(etag) : NULL; update->hash = dav_create_hash(buf->space, buf->size); updates = ucx_list_append(updates, update); + + block_end = offset+buf->size; + } else { + if(offset+blocksize > end) { + // if we don't download the block, we don't know the size + // but it can't be bigger than the file + block_end = end; + } else { + block_end = offset+blocksize; + } } - + if(block_end > maxsize) { + maxsize = block_end; + } i++; } // else: res is not a regular file part @@ -1038,9 +1052,14 @@ return NULL; } + if(maxsize < end) { + *truncate_file = maxsize; + } else { + *truncate_file = -1; + } + *err = 0; *blockcount = i; - *truncate_file = maxsize; return updates; }