aboutsummaryrefslogtreecommitdiff
path: root/ftp/curl/files/patch-src-tool_operate.c
blob: 77ab0a758e2b26a0a84e54e2d527d2ea25d444b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--- src/tool_operate.c.orig	2019-09-10 17:47:19 UTC
+++ src/tool_operate.c
@@ -960,20 +960,7 @@ static CURLcode create_transfers(struct 
             DEBUGASSERT(!outs->filename);
           }
 
-          if(config->resume_from_current) {
-            /* We're told to continue from where we are now. Get the size
-               of the file as it is now and open it for append instead */
-            struct_stat fileinfo;
-            /* VMS -- Danger, the filesize is only valid for stream files */
-            if(0 == stat(per->outfile, &fileinfo))
-              /* set offset to current file size: */
-              config->resume_from = fileinfo.st_size;
-            else
-              /* let offset be 0 */
-              config->resume_from = 0;
-          }
-
-          if(config->resume_from) {
+          if(config->resume_from || config->resume_from_current) {
 #ifdef __VMS
             /* open file for output, forcing VMS output format into stream
                mode which is needed for stat() call above to always work. */
@@ -981,7 +968,8 @@ static CURLcode create_transfers(struct 
                                "ctx=stm", "rfm=stmlf", "rat=cr", "mrs=0");
 #else
             /* open file for output: */
-            FILE *file = fopen(per->outfile, config->resume_from?"ab":"wb");
+            /* (always open for appending, it has no effect on new files) */
+            FILE *file = fopen(per->outfile, "ab");
 #endif
             if(!file) {
               helpf(global->errors, "Can't open '%s'!\n", per->outfile);
@@ -990,6 +978,19 @@ static CURLcode create_transfers(struct 
             }
             outs->fopened = TRUE;
             outs->stream = file;
+
+            if(config->resume_from_current) {
+              /* We're told to continue from where we are now. Get the size
+                 of the file as it is now */
+              struct_stat fileinfo;
+              if(0 == fstat(fileno(outs->stream), &fileinfo))
+                /* set offset to current file size: */
+                config->resume_from = fileinfo.st_size;
+              else
+                /* let offset be 0 */
+                config->resume_from = 0;
+            }
+
             outs->init = config->resume_from;
           }
           else {