]> git.saurik.com Git - apt.git/blobdiff - methods/ftp.cc
apply various suggestions made by cppcheck
[apt.git] / methods / ftp.cc
index 0504e58724f253025f1191282d2e0803af59b1f9..a8bc95938f5c47ad2341de40f809a50c1ff8dd34 100644 (file)
@@ -39,7 +39,6 @@
 
 // Internet stuff
 #include <netinet/in.h>
 
 // Internet stuff
 #include <netinet/in.h>
-#include <sys/socket.h>
 #include <arpa/inet.h>
 #include <netdb.h>
 
 #include <arpa/inet.h>
 #include <netdb.h>
 
@@ -259,19 +258,21 @@ bool FTPConn::Login()
       {
         if (Opts->Value.empty() == true)
            continue;
       {
         if (Opts->Value.empty() == true)
            continue;
-        
+
         // Substitute the variables into the command
         // Substitute the variables into the command
-        char SitePort[20];
-        if (ServerName.Port != 0)
-           sprintf(SitePort,"%u",ServerName.Port);
-        else
-           strcpy(SitePort,"21");
         string Tmp = Opts->Value;
         Tmp = SubstVar(Tmp,"$(PROXY_USER)",Proxy.User);
         Tmp = SubstVar(Tmp,"$(PROXY_PASS)",Proxy.Password);
         Tmp = SubstVar(Tmp,"$(SITE_USER)",User);
         Tmp = SubstVar(Tmp,"$(SITE_PASS)",Pass);
         string Tmp = Opts->Value;
         Tmp = SubstVar(Tmp,"$(PROXY_USER)",Proxy.User);
         Tmp = SubstVar(Tmp,"$(PROXY_PASS)",Proxy.Password);
         Tmp = SubstVar(Tmp,"$(SITE_USER)",User);
         Tmp = SubstVar(Tmp,"$(SITE_PASS)",Pass);
-        Tmp = SubstVar(Tmp,"$(SITE_PORT)",SitePort);
+        if (ServerName.Port != 0)
+        {
+           std::string SitePort;
+           strprintf(SitePort, "%u", ServerName.Port);
+           Tmp = SubstVar(Tmp,"$(SITE_PORT)", SitePort);
+        }
+        else
+           Tmp = SubstVar(Tmp,"$(SITE_PORT)", "21");
         Tmp = SubstVar(Tmp,"$(SITE)",ServerName.Host);
 
         // Send the command
         Tmp = SubstVar(Tmp,"$(SITE)",ServerName.Host);
 
         // Send the command
@@ -744,7 +745,7 @@ bool FTPConn::CreateDataFd()
    }
    
    // Bind and listen
    }
    
    // Bind and listen
-   if (bind(DataListenFd,BindAddr->ai_addr,BindAddr->ai_addrlen) < 0)
+   if (::bind(DataListenFd,BindAddr->ai_addr,BindAddr->ai_addrlen) < 0)
    {
       freeaddrinfo(BindAddr);
       return _error->Errno("bind",_("Could not bind a socket"));
    {
       freeaddrinfo(BindAddr);
       return _error->Errno("bind",_("Could not bind a socket"));
@@ -949,7 +950,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
 // FtpMethod::FtpMethod - Constructor                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // FtpMethod::FtpMethod - Constructor                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-FtpMethod::FtpMethod() : pkgAcqMethod("1.0",SendConfig)
+FtpMethod::FtpMethod() : aptMethod("ftp","1.0",SendConfig)
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
@@ -984,13 +985,10 @@ void FtpMethod::SigTerm(int)
 /* We stash the desired pipeline depth */
 bool FtpMethod::Configuration(string Message)
 {
 /* We stash the desired pipeline depth */
 bool FtpMethod::Configuration(string Message)
 {
-   if (pkgAcqMethod::Configuration(Message) == false)
+   if (aptMethod::Configuration(Message) == false)
       return false;
       return false;
-   
-   TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
 
 
-   // no more active ftp, sorry
-   DropPrivsOrDie();
+   TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
 
    return true;
 }
 
    return true;
 }
@@ -1062,7 +1060,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
    }
    
    // Open the file
    }
    
    // Open the file
-   Hashes Hash;
+   Hashes Hash(Itm->ExpectedHashes);
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
@@ -1071,7 +1069,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       URIStart(Res);
       
       FailFile = Itm->DestFile;
       URIStart(Res);
       
       FailFile = Itm->DestFile;
-      FailFile.c_str();   // Make sure we dont do a malloc in the signal handler
+      FailFile.c_str();   // Make sure we don't do a malloc in the signal handler
       FailFd = Fd.Fd();
       
       bool Missing;
       FailFd = Fd.Fd();
       
       bool Missing;
@@ -1089,7 +1087,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
         // If the file is missing we hard fail and delete the destfile
         // otherwise transient fail
         if (Missing == true) {
         // If the file is missing we hard fail and delete the destfile
         // otherwise transient fail
         if (Missing == true) {
-           unlink(FailFile.c_str());
+           RemoveFile("ftp", FailFile);
            return false;
         }
         Fail(true);
            return false;
         }
         Fail(true);