- Use CURLOPT_NOBODY instead of a CURLOPT_RANGE of 1 byte
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Sat, 16 Feb 2008 14:56:39 +0000 (14:56 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Sat, 16 Feb 2008 14:56:39 +0000 (14:56 +0000)
  for http and https, but this time set CURLOPT_HTTPGET back to 1
  so it actually works. This makes Media::doesFileExist
  efficient for http and https.
  (bnc #348050)
- version 4.2.5

VERSION.cmake
package/libzypp.changes
zypp/media/MediaCurl.cc

index 3f448cf..f650bb1 100644 (file)
@@ -47,4 +47,4 @@
 SET(LIBZYPP_MAJOR "4")
 SET(LIBZYPP_MINOR "2")
 SET(LIBZYPP_COMPATMINOR "2")
-SET(LIBZYPP_PATCH "4")
+SET(LIBZYPP_PATCH "5")
index 5b799df..4b06b05 100644 (file)
@@ -1,4 +1,14 @@
 -------------------------------------------------------------------
+Fri Feb 16 15:47:00 CET 2008 - dmacvicar@suse.de
+
+- Use CURLOPT_NOBODY instead of a CURLOPT_RANGE of 1 byte
+  for http and https, but this time set CURLOPT_HTTPGET back to 1
+  so it actually works. This makes Media::doesFileExist
+  efficient for http and https.
+  (bnc #348050)
+- version 4.2.5
+
+-------------------------------------------------------------------
 Fri Feb 15 10:52:59 CET 2008 - coolo@suse.de
 
 - using .solv files only now (fate #303018)
index 6035831..161343a 100644 (file)
@@ -868,26 +868,40 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
     ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
   }
 
-  // set no data, because we only want to check if the file exists
-  //ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, 1 );
-  //if ( ret != 0 ) {
-  //    ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
-  //}
-
   // instead of returning no data with NOBODY, we return
   // little data, that works with broken servers, and
   // works for ftp as well, because retrieving only headers
   // ftp will return always OK code ?
-  ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" );
+  if (  _url.getScheme() == "http" ||  _url.getScheme() == "https" )
+    ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, 1 );
+  else
+    ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" );
+
   if ( ret != 0 ) {
-      ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
+    curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
+    curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+    /* yes, this is why we never got to get NOBODY working before,
+       because setting it changes this option too, and we also
+       need to reset it
+       See: http://curl.haxx.se/mail/archive-2005-07/0073.html
+    */
+    curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
+    ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
   }
 
+
   FILE *file = ::fopen( "/dev/null", "w" );
   if ( !file ) {
       ::fclose(file);
       ERR << "fopen failed for /dev/null" << endl;
+      curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
       curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+      /* yes, this is why we never got to get NOBODY working before,
+       because setting it changes this option too, and we also
+       need to reset it
+       See: http://curl.haxx.se/mail/archive-2005-07/0073.html
+      */
+      curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
       if ( ret != 0 ) {
           ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
       }
@@ -899,6 +913,13 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
       ::fclose(file);
       std::string err( _curlError);
       curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+      curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
+      /* yes, this is why we never got to get NOBODY working before,
+       because setting it changes this option too, and we also
+       need to reset it
+       See: http://curl.haxx.se/mail/archive-2005-07/0073.html
+      */
+      curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
       if ( ret != 0 ) {
           ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
       }
@@ -915,7 +936,19 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
   MIL << "perform code: " << ok << " [ " << curl_easy_strerror(ok) << " ]" << endl;
 
   // reset curl settings
-  ret = curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+  if (  _url.getScheme() == "http" ||  _url.getScheme() == "https" )
+  {
+    ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
+    /* yes, this is why we never got to get NOBODY working before,
+       because setting it changes this option too, and we also
+       need to reset it
+       See: http://curl.haxx.se/mail/archive-2005-07/0073.html
+    */
+    ret = curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
+  }
+  else
+    ret = curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
+
   if ( ret != 0 )
   {
     ZYPP_THROW(MediaCurlSetOptException(url, _curlError));