Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #357 from braydonf/master
Browse files Browse the repository at this point in the history
Fix windows bug when recovering the last shard
  • Loading branch information
aleitner authored Jun 28, 2017
2 parents 653b398 + 22b1efe commit 94095da
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/downloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,37 @@ static void recover_shards(uv_work_t *work)
uint64_t bytes_decrypted = 0;
size_t len = AES_BLOCK_SIZE * 8;

// Make sure that the file is the correct size before recovering
// shards in case that the last shard is the one being recovered.
#ifdef _WIN32

HANDLE prefile = (HANDLE)_get_osfhandle(req->fd);
if (prefile == INVALID_HANDLE_VALUE) {
req->error_status = STORJ_FILE_RESIZE_ERROR;
return;
}

LARGE_INTEGER presize;
presize.HighPart = (uint32_t)((req->filesize & 0xFFFFFFFF00000000LL) >> 32);
presize.LowPart = (uint32_t)(req->filesize & 0xFFFFFFFFLL);

if (!SetFilePointerEx(prefile, presize, 0, FILE_BEGIN)) {
req->error_status = STORJ_FILE_RESIZE_ERROR;
return;
}

if (!SetEndOfFile(prefile)) {
req->error_status = STORJ_FILE_RESIZE_ERROR;
return;
}

#else
if (ftruncate(req->fd, req->filesize)) {
// errno for more details
req->error_status = STORJ_FILE_RESIZE_ERROR;
}
#endif

error = map_file(req->fd, req->filesize, &data_map, false);
if (error) {
req->error_status = STORJ_MAPPING_ERROR;
Expand Down

0 comments on commit 94095da

Please sign in to comment.