Merge branch 'debian/sid' into ubuntu/master
[ntk/apt.git] / methods / server.cc
index a212844..ef90c80 100644 (file)
@@ -17,9 +17,9 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/netrc.h>
 
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <utime.h>
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -86,7 +86,7 @@ ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File)
       if (Result == 100)
         continue;
       
-      // Tidy up the connection persistance state.
+      // Tidy up the connection persistence state.
       if (Encoding == Closes && HaveContent == true)
         Persistent = false;
       
@@ -146,7 +146,7 @@ bool ServerState::HeaderLine(string Line)
            return _error->Error(_("The HTTP server sent an invalid reply header"));
       }
 
-      /* Check the HTTP response header to get the default persistance
+      /* Check the HTTP response header to get the default persistence
          state. */
       if (Major < 1)
         Persistent = false;
@@ -291,11 +291,15 @@ ServerMethod::DealWithHeaders(FetchResult &Res)
       }
       else
       {
-         NextURI = DeQuoteString(Server->Location);
-         URI tmpURI = NextURI;
-         // Do not allow a redirection to switch protocol
-         if (tmpURI.Access == "http")
-            return TRY_AGAIN_OR_REDIRECT;
+        NextURI = DeQuoteString(Server->Location);
+        URI tmpURI = NextURI;
+        URI Uri = Queue->Uri;
+        // same protocol redirects are okay
+        if (tmpURI.Access == Uri.Access)
+           return TRY_AGAIN_OR_REDIRECT;
+        // as well as http to https
+        else if (Uri.Access == "http" && tmpURI.Access == "https")
+           return TRY_AGAIN_OR_REDIRECT;
       }
       /* else pass through for error message */
    }
@@ -362,20 +366,20 @@ ServerMethod::DealWithHeaders(FetchResult &Res)
                                                                        /*}}}*/
 // ServerMethod::SigTerm - Handle a fatal signal                       /*{{{*/
 // ---------------------------------------------------------------------
-/* This closes and timestamps the open file. This is neccessary to get
+/* This closes and timestamps the open file. This is necessary to get
    resume behavoir on user abort */
 void ServerMethod::SigTerm(int)
 {
    if (FailFd == -1)
       _exit(100);
+
+   struct timeval times[2];
+   times[0].tv_sec = FailTime;
+   times[1].tv_sec = FailTime;
+   times[0].tv_usec = times[1].tv_usec = 0;
+   utimes(FailFile.c_str(), times);
    close(FailFd);
-   
-   // Timestamp
-   struct utimbuf UBuf;
-   UBuf.actime = FailTime;
-   UBuf.modtime = FailTime;
-   utime(FailFile.c_str(),&UBuf);
-   
+
    _exit(100);
 }
                                                                        /*}}}*/
@@ -539,11 +543,10 @@ int ServerMethod::Loop()
            File = 0;
            
            // Timestamp
-           struct utimbuf UBuf;
-           time(&UBuf.actime);
-           UBuf.actime = Server->Date;
-           UBuf.modtime = Server->Date;
-           utime(Queue->DestFile.c_str(),&UBuf);
+           struct timeval times[2];
+           times[0].tv_sec = times[1].tv_sec = Server->Date;
+           times[0].tv_usec = times[1].tv_usec = 0;
+           utimes(Queue->DestFile.c_str(), times);
 
            // Send status to APT
            if (Result == true)