aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-05-31 08:59:44 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-05-31 08:59:44 +0000
commit713c9f8602caf53db2159b3db7d863f15174e987 (patch)
treea9f3e5a4804058f3d3ce7e0b31a84707de3df5a5
parent14b9b823e6a3d3584d6ee724b60485b1afda5652 (diff)
Feng Tu made (lib)curl support "upload" resuming work for file:// URLs.
-rw-r--r--CHANGES4
-rw-r--r--RELEASE-NOTES1
-rw-r--r--lib/file.c37
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;