[Cmake-commits] [cmake-commits] hoffman committed cmFileCommand.h 1.48 1.49 cmFileCommand.cxx 1.141 1.142

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Oct 22 09:45:01 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv21678

Modified Files:
	cmFileCommand.h cmFileCommand.cxx 
Log Message:
Fix up download a bit, better error checking and uses of long not double for timeout as curl needs, bug# 9748


Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -C 2 -d -r1.48 -r1.49
*** cmFileCommand.h	28 Sep 2009 15:42:31 -0000	1.48
--- cmFileCommand.h	22 Oct 2009 13:44:57 -0000	1.49
***************
*** 153,157 ****
        "numeric error means no error in the operation. "
        "If TIMEOUT time is specified, the operation will "
!       "timeout after time seconds, time can be specified as a float."
        "\n"
        "The file() command also provides COPY and INSTALL signatures:\n"
--- 153,157 ----
        "numeric error means no error in the operation. "
        "If TIMEOUT time is specified, the operation will "
!       "timeout after time seconds, time should be specified as an integer."
        "\n"
        "The file() command also provides COPY and INSTALL signatures:\n"

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.141
retrieving revision 1.142
diff -C 2 -d -r1.141 -r1.142
*** cmFileCommand.cxx	17 Oct 2009 15:43:15 -0000	1.141
--- cmFileCommand.cxx	22 Oct 2009 13:44:58 -0000	1.142
***************
*** 2466,2480 ****
        = static_cast<cmFileCommandVectorOfChar*>(data);
      vec->insert(vec->end(), chPtr, chPtr + size);
!     
      return size;
    }
!   
!   
  }
  
  #endif
  
! bool 
! cmFileCommand::HandleDownloadCommand(std::vector<std::string> 
                                       const& args)
  {
--- 2466,2511 ----
        = static_cast<cmFileCommandVectorOfChar*>(data);
      vec->insert(vec->end(), chPtr, chPtr + size);
! 
      return size;
    }
! 
! 
  }
  
  #endif
  
! #if defined(CMAKE_BUILD_WITH_CMAKE)
! namespace {
! 
!   class cURLEasyGuard
!   {
!   public:
!     cURLEasyGuard(CURL * easy)
!       : Easy(easy)
!       {}
!     
!     ~cURLEasyGuard(void) 
!       {
!         if (this->Easy)
!           {
!           ::curl_easy_cleanup(this->Easy);
!           }
!       }
!     
!     inline void release(void) 
!       {
!         this->Easy = 0;
!         return;
!       }
!     
!   private:
!     ::CURL * Easy;
!   };
!   
! }
! #endif
! 
! bool
! cmFileCommand::HandleDownloadCommand(std::vector<std::string>
                                       const& args)
  {
***************
*** 2487,2496 ****
      return false;
      }
!   i++; // Get rid of subcommand
    std::string url = *i;
!   i++;
    std::string file = *i;
!   i++;
!   double timeout = 0;
    std::string verboseLog;
    std::string statusVar;
--- 2518,2527 ----
      return false;
      }
!   ++i; // Get rid of subcommand
    std::string url = *i;
!   ++i;
    std::string file = *i;
!   ++i;
!   long timeout = 0;
    std::string verboseLog;
    std::string statusVar;
***************
*** 2499,2509 ****
      if(*i == "TIMEOUT")
        {
!       i++;
        if(i != args.end())
          {
!         timeout = atof(i->c_str());
          }
        else
!         { 
          this->SetError("FILE(DOWNLOAD url file TIMEOUT time) missing "
                         "time for TIMEOUT.");
--- 2530,2540 ----
      if(*i == "TIMEOUT")
        {
!       ++i;
        if(i != args.end())
          {
!         timeout = atol(i->c_str());
          }
        else
!         {
          this->SetError("FILE(DOWNLOAD url file TIMEOUT time) missing "
                         "time for TIMEOUT.");
***************
*** 2513,2517 ****
      else if(*i == "LOG")
        {
!       i++;
        if( i == args.end())
          {
--- 2544,2548 ----
      else if(*i == "LOG")
        {
!       ++i;
        if( i == args.end())
          {
***************
*** 2524,2528 ****
      else if(*i == "STATUS")
        {
!       i++;
        if( i == args.end())
          {
--- 2555,2559 ----
      else if(*i == "STATUS")
        {
!       ++i;
        if( i == args.end())
          {
***************
*** 2533,2537 ****
        statusVar = *i;
        }
!     i++;
      }
  
--- 2564,2568 ----
        statusVar = *i;
        }
!     ++i;
      }
  
***************
*** 2554,2560 ****
      return false;
      }
!   CURL *curl;
!   curl_global_init(CURL_GLOBAL_DEFAULT);
!   curl = curl_easy_init();
    if(!curl)
      {
--- 2585,2591 ----
      return false;
      }
!   ::CURL *curl;
!   ::curl_global_init(CURL_GLOBAL_DEFAULT);
!   curl = ::curl_easy_init();
    if(!curl)
      {
***************
*** 2563,2601 ****
      return false;
      }
!   
!   curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
!   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, 
!                    cmFileCommandWriteMemoryCallback);
!   curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
!                    cmFileCommandCurlDebugCallback);
    cmFileCommandVectorOfChar chunkDebug;
!   ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&fout);
!   ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
    if(verboseLog.size())
      {
!     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
      }
    if(timeout > 0)
      {
!     curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout ); 
      }
!   CURLcode res = curl_easy_perform(curl);
    /* always cleanup */
!   curl_easy_cleanup(curl);
    if(statusVar.size())
      {
      cmOStringStream result;
!     result << (int)res << ";\"" << curl_easy_strerror(res) << "\"";
!     this->Makefile->AddDefinition(statusVar.c_str(), 
                                    result.str().c_str());
      }
!   curl_global_cleanup();
    if(chunkDebug.size())
      {
      chunkDebug.push_back(0);
      if(CURLE_OPERATION_TIMEOUTED == res)
!       { 
        std::string output = &*chunkDebug.begin();
!       
        if(verboseLog.size())
          {
--- 2594,2688 ----
      return false;
      }
! 
!   cURLEasyGuard g_curl(curl);
! 
!   ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
!   if (res != CURLE_OK)
!     {
!       std::string errstring = "FILE(DOWNLOAD ) error; cannot set url: ";
!       errstring += ::curl_easy_strerror(res);
!     return false;
!     }
! 
!   res = ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
!                              cmFileCommandWriteMemoryCallback);
!   if (res != CURLE_OK)
!       {
!       std::string errstring =
!         "FILE(DOWNLOAD ) error; cannot set write function: ";
!       errstring += ::curl_easy_strerror(res);
!     return false;
!     }
! 
!   res = ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
!                              cmFileCommandCurlDebugCallback);
!   if (res != CURLE_OK)
!     {
!      std::string errstring =
!        "FILE(DOWNLOAD ) error; cannot set debug function: ";
!      errstring += ::curl_easy_strerror(res);
!     return false;
!     }
! 
    cmFileCommandVectorOfChar chunkDebug;
! 
!   res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&fout);
! 
!   if (res != CURLE_OK)
!     {
!     std::string errstring = "FILE(DOWNLOAD ) error; cannot set write data: ";
!     errstring += ::curl_easy_strerror(res);
!     return false;
!     }
! 
!   res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)&chunkDebug);
!   if (res != CURLE_OK)
!     {
!     std::string errstring = "FILE(DOWNLOAD ) error; cannot set write data: ";
!     errstring += ::curl_easy_strerror(res);
!     return false;
!     }
! 
    if(verboseLog.size())
      {
!     res = ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
! 
!     if (res != CURLE_OK)
!       {
!       std::string errstring = "FILE(DOWNLOAD ) error; cannot set verbose: ";
!       errstring += ::curl_easy_strerror(res);
!       return false;
!       }
      }
    if(timeout > 0)
      {
!     res = ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout );
! 
!     if (res != CURLE_OK)
!       {
!       std::string errstring = "FILE(DOWNLOAD ) error; cannot set verbose: ";
!       errstring += ::curl_easy_strerror(res);
!       return false;
!       }
      }
!   res = ::curl_easy_perform(curl);
    /* always cleanup */
!   g_curl.release();
!   ::curl_easy_cleanup(curl);
    if(statusVar.size())
      {
      cmOStringStream result;
!     result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
!     this->Makefile->AddDefinition(statusVar.c_str(),
                                    result.str().c_str());
      }
!   ::curl_global_cleanup();
    if(chunkDebug.size())
      {
      chunkDebug.push_back(0);
      if(CURLE_OPERATION_TIMEOUTED == res)
!       {
        std::string output = &*chunkDebug.begin();
! 
        if(verboseLog.size())
          {
***************
*** 2609,2616 ****
      }
    return true;
! #else 
    this->SetError("FILE(DOWNLOAD ) "
                   "not supported in bootstrap cmake ");
    return false;
! #endif  
  }
--- 2696,2703 ----
      }
    return true;
! #else
    this->SetError("FILE(DOWNLOAD ) "
                   "not supported in bootstrap cmake ");
    return false;
! #endif
  }



More information about the Cmake-commits mailing list