Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-updates-src > by-pkgid > 2766ce3c97ef80dabe7bfedbeb841b8d > files > 3

wget-1.15-5.2.mga5.src.rpm

--- wget-1.15/src/http.c.orig	2014-01-07 09:58:49.000000000 -0500
+++ wget-1.15/src/http.c	2016-09-12 19:49:18.692200103 -0400
@@ -39,6 +39,8 @@ as that of the covered work.  */
 #include <errno.h>
 #include <time.h>
 #include <locale.h>
+#include <fcntl.h>
+
 
 #include "hash.h"
 #include "http.h"
@@ -1450,6 +1452,7 @@ struct http_stat
   wgint orig_file_size;         /* size of file to compare for time-stamping */
   time_t orig_file_tstamp;      /* time-stamp of file to compare for
                                  * time-stamping */
+  bool temporary;               /* downloading a temporary file */
 };
 
 static void
@@ -2460,6 +2463,15 @@ read_header:
         }
     }
 
+  hs->temporary = opt.delete_after || opt.spider || !acceptable (hs->local_file);
+  if (hs->temporary)
+    {
+      char *tmp = NULL;
+      asprintf (&tmp, "%s.tmp", hs->local_file);
+      xfree (hs->local_file);
+      hs->local_file = tmp;
+    }
+
   /* TODO: perform this check only once. */
   if (!hs->existence_checked && file_exists_p (hs->local_file))
     {
@@ -2891,7 +2903,11 @@ read_header:
           open_id = 22;
           fp = fopen (hs->local_file, "wb", FOPEN_OPT_ARGS);
 #else /* def __VMS */
-          fp = fopen (hs->local_file, "wb");
+          if (hs->temporary)
+              fp = fdopen (open (hs->local_file, O_BINARY | O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR), "wb");
+          else
+              fp = fopen (hs->local_file, "wb");
+
 #endif /* def __VMS [else] */
         }
       else