From 314f408b5ef50ae7e2b4d56beb11c858771fc395 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 1 Oct 2018 01:40:49 -0500 Subject: [PATCH] Report a disk switch if the length of the file changed. Currently, the logic for this doesn't re-detect the file type, and it may not work correctly with some 2mg files, but it should work in most cases. --- driver.c | 13 ++++++++++++- http.c | 4 +++- netdiskerror.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/driver.c b/driver.c index 736c1b9..69d2426 100644 --- a/driver.c +++ b/driver.c @@ -337,7 +337,18 @@ static Word DoRead(struct GSOSDP *dp) { enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd); if (err != OPERATION_SUCCESSFUL) { dp->transferCount = 0; - return drvrIOError; + if (err == DIFFERENT_LENGTH) { + if ((sess->totalLength - sess->dataOffset) % BLOCK_SIZE != 0) { + return drvrIOError; + } else { + sess->dataLength = sess->totalLength - sess->dataOffset; + dp->dibPointer->blockCount = sess->dataLength / BLOCK_SIZE; + sess->expectedLength = sess->totalLength; + return drvrDiskSwitch; + } + } else { + return drvrIOError; + } } ReadStatus readStatus; diff --git a/http.c b/http.c index 59781ca..7754bb5 100644 --- a/http.c +++ b/http.c @@ -363,7 +363,9 @@ netRetry: } /* See if we got what we wanted */ - if (sess->expectedLength != 0 && sess->totalLength != sess->expectedLength) { + if (sess->expectedLength == 0) { + sess->expectedLength = sess->totalLength; + } else if (sess->totalLength != sess->expectedLength) { result = DIFFERENT_LENGTH; goto errorReturn; } diff --git a/netdiskerror.h b/netdiskerror.h index 4aa6a58..543344d 100644 --- a/netdiskerror.h +++ b/netdiskerror.h @@ -31,7 +31,7 @@ enum NetDiskError { UNSUPPORTED_HEADER_VALUE, REDIRECT_ERROR, NOT_DESIRED_CONTENT, - DIFFERENT_LENGTH, /* Might be considered successful later */ + DIFFERENT_LENGTH, /* Error values of 4xx and 5xx mean we got the corresponding HTTP error */ HTTP_ERROR = 400,