Hrvoje Niksic wrote:
> Jeroen Demeyer <[EMAIL PROTECTED]> writes:
> 
> 
>>I am a big fan of wget, but I discovered a minor annoyance (not sure
>>if it even is a bug):
>>
>>When downloading multiple files with wget to a single output
>>(e.g. wget -Oout http://file1 http://file2 http://file3), the
>>timestamp of the resulting file becomes the timestamp of the *last*
>>file downloaded.
>>
>>I think it would make more sense if the timestamp would be the
>>timestamp of the most recent file downloaded.
> 
> 
> It probably doesn't makes sense to set *any* explicit timestamp on
> file created with -O from multiple URLs.  Current behavior is merely a
> side-effect of the implementation.  But just removing the code that
> sets the time-stamp would break the behavior for people who use -O
> with single URL.
> 
> Changing the current behavior would require complexifying that part of
> the code; I'm not sure that anything would be gained by such a change.
> Do you have a use case that breaks on current behavior that would be
> fixed by introducing the change?

How about something like this?  (see attachment).  This works for me.
Note that I have zero experience with wget hacking, so I have no idea
what this might break.

Jeroen
Index: src/http.c
===================================================================
--- src/http.c  (revision 2042)
+++ src/http.c  (working copy)
@@ -1995,6 +1995,7 @@
   const char *tmrate;
   uerr_t err;
   time_t tml = -1, tmr = -1;   /* local and remote time-stamps */
+  time_t mintmtouch = -1;              /* minimum time-stamp for the local 
file */
   wgint local_size = 0;                /* the size of the local file */
   size_t filename_len;
   struct http_stat hstat;      /* HTTP status */
@@ -2124,6 +2125,20 @@
          got_head = false;
        }
     }
+
+       /* Look at modification time of our output_document.  If we concatenate
+          multiple documents, we want the resulting local timestamp to be the
+          maximum of all remote time-stamps.  In other words, we should never
+          touch the output_document such that it becomes older. */
+       if (opt.output_document && output_stream_regular)
+       {
+               if (stat (opt.output_document, &st) == 0)
+               /* If the file is empty and always_rest is off,
+                  then ignore the modification time. */
+                       if (st.st_size > 0 || opt.always_rest)
+                               mintmtouch = st.st_mtime;
+       }
+  
   /* Reset the counter.  */
   count = 0;
   *dt = 0;
@@ -2368,7 +2383,8 @@
          else
            fl = *hstat.local_file;
          if (fl)
-           touch (fl, tmr);
+           /* the time becomes the maximum of mintmtouch and tmr */
+           touch (fl, (mintmtouch != (time_t) (-1) && mintmtouch > tmr) ? 
mintmtouch : tmr);
        }
       /* End of time-stamping section.  */
 

Reply via email to