Mailinglist Archive: zypp-commit (301 mails)

< Previous Next >
[zypp-commit] r7456 - /trunk/libzypp/zypp/media/MediaCurl.cc
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Sat, 06 Oct 2007 15:28:32 -0000
  • Message-id: <20071006152832.72888173CF@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Sat Oct  6 17:28:32 2007
New Revision: 7456

URL: http://svn.opensuse.org/viewcvs/zypp?rev=7456&view=rev
Log:
- do not download the same file multiple times in one attach session
  (#307098)

Modified:
    trunk/libzypp/zypp/media/MediaCurl.cc

Modified: trunk/libzypp/zypp/media/MediaCurl.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/media/MediaCurl.cc?rev=7456&r1=7455&r2=7456&view=diff
==============================================================================
--- trunk/libzypp/zypp/media/MediaCurl.cc (original)
+++ trunk/libzypp/zypp/media/MediaCurl.cc Sat Oct  6 17:28:32 2007
@@ -1100,6 +1100,10 @@
       ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
     }
 
+    // set IFMODSINCE time condition (no download if not modified)
+    curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+    curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, PathInfo(target).mtime());
+
     string destNew = target.asString() + ".new.zypp.XXXXXX";
     char *buf = ::strdup( destNew.c_str());
     if( !buf)
@@ -1299,16 +1303,48 @@
     }
 #endif // DETECT_DIR_INDEX
 
-    if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
+    long httpReturnCode = 0;
+    CURLcode infoRet = curl_easy_getinfo(_curl,
+                                         CURLINFO_RESPONSE_CODE,
+                                         &httpReturnCode);
+    bool modified = true;
+    if (infoRet == CURLE_OK)
     {
-      ERR << "Failed to chmod file " << destNew << endl;
+      DBG << "HTTP response: " + str::numstring(httpReturnCode);
+      if ( httpReturnCode == 304 ) // not modified
+      {
+        DBG << " Not modified.";
+        modified = false;
+      }
+      DBG << endl;
     }
-    ::fclose( file );
+    else
+    {
+      WAR << "Could not get the reponse code." << endl;
+    }
+
+    if (modified || infoRet != CURLE_OK)
+    {
+      // apply umask
+      if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
+      {
+        ERR << "Failed to chmod file " << destNew << endl;
+      }
+      ::fclose( file );
 
-    if ( rename( destNew, dest ) != 0 ) {
-      ERR << "Rename failed" << endl;
-      ZYPP_THROW(MediaWriteException(dest));
+      // move the temp file into dest
+      if ( rename( destNew, dest ) != 0 ) {
+        ERR << "Rename failed" << endl;
+        ZYPP_THROW(MediaWriteException(dest));
+      }
     }
+    else
+    {
+      // close and remove the temp file
+      ::fclose( file );
+      filesystem::unlink( destNew );
+    }
+
     DBG << "done: " << PathInfo(dest) << endl;
 }
 

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages