From 713c9f8602caf53db2159b3db7d863f15174e987 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 May 2007 08:59:44 +0000 Subject: Feng Tu made (lib)curl support "upload" resuming work for file:// URLs. --- CHANGES | 4 ++++ RELEASE-NOTES | 1 + lib/file.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 83a2d393c..764210e37 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ \___|\___/|_| \_\_____| Changelog + +Daniel S (31 May 2007) +- Feng Tu made (lib)curl support "upload" resuming work for file:// URLs. + Daniel S (30 May 2007) - Added CURLMOPT_MAXCONNECTS which is a curl_multi_setopt() option for setting the maximum size of the connection cache maximum size of the multi handle. diff --git a/RELEASE-NOTES b/RELEASE-NOTES index dc520319b..591034fce 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -18,6 +18,7 @@ This release includes the following changes: o more than one test harness can run at the same time without conflict o SFTP now supports quote commands before a transfer o CURLMOPT_MAXCONNECTS added to curl_multi_setopt() + o upload resume works for file:// URLs This release includes the following bugfixes: diff --git a/lib/file.c b/lib/file.c index 3fc1663d1..3c37f6084 100644 --- a/lib/file.c +++ b/lib/file.c @@ -198,6 +198,8 @@ static CURLcode file_upload(struct connectdata *conn) size_t nwrite; curl_off_t bytecount = 0; struct timeval now = Curl_tvnow(); + struct_stat file_stat; + char* buf2; /* * Since FILE: doesn't do the full init, we need to provide some extra @@ -213,7 +215,11 @@ static CURLcode file_upload(struct connectdata *conn) if(!dir[1]) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ - fp = fopen(file->path, "wb"); + if(data->reqdata.resume_from) + fp = fopen( file->path, "ab" ); + else + fp = fopen(file->path, "wb"); + if(!fp) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; @@ -223,6 +229,17 @@ static CURLcode file_upload(struct connectdata *conn) /* known size of data to "upload" */ Curl_pgrsSetUploadSize(data, data->set.infilesize); + /* treat the negative resume offset value as the case of "-" */ + if(data->reqdata.resume_from < 0){ + if(stat(file->path, &file_stat)){ + fclose(fp); + failf(data, "Can't get the size of %s", file->path); + return CURLE_WRITE_ERROR; + } + else + data->reqdata.resume_from = (curl_off_t)file_stat.st_size; + } + while (res == CURLE_OK) { int readcount; res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount); @@ -234,8 +251,24 @@ static CURLcode file_upload(struct connectdata *conn) nread = (size_t)readcount; + /*skip bytes before resume point*/ + if(data->reqdata.resume_from) { + if( nread <= data->reqdata.resume_from ) { + data->reqdata.resume_from -= nread; + nread = 0; + buf2 = buf; + } + else { + buf2 = buf + data->reqdata.resume_from; + nread -= data->reqdata.resume_from; + data->reqdata.resume_from = 0; + } + } + else + buf2 = buf; + /* write the data to the target */ - nwrite = fwrite(buf, 1, nread, fp); + nwrite = fwrite(buf2, 1, nread, fp); if(nwrite != nread) { res = CURLE_SEND_ERROR; break; -- cgit v1.2.3