]> git.saurik.com Git - apt.git/blobdiff - methods/ftp.cc
rewrite all TFRewrite instances to use the new pkgTagSection::Write
[apt.git] / methods / ftp.cc
index 75ace1c5a4e1b7198f984b8d357ea095ab15e61a..92d8573f1071839744f88f8fd4fb211f91a7c352 100644 (file)
@@ -259,19 +259,21 @@ bool FTPConn::Login()
       {
         if (Opts->Value.empty() == true)
            continue;
-        
+
         // 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);
-        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
@@ -849,7 +851,8 @@ bool FTPConn::Finalize()
 /* This opens a data connection, sends REST and RETR and then
    transfers the file over. */
 bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
-                 Hashes &Hash,bool &Missing, unsigned long long ExpectedSize)
+                 Hashes &Hash,bool &Missing, unsigned long long MaximumSize,
+                  pkgAcqMethod *Owner)
 {
    Missing = false;
    if (CreateDataFd() == false)
@@ -924,9 +927,12 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
         return false;
       }
 
-      if (ExpectedSize > 0 && To.Tell() > ExpectedSize)
+      if (MaximumSize > 0 && To.Tell() > MaximumSize)
+      {
+         Owner->SetFailReason("MaximumSizeExceeded");
          return _error->Error("Writing more data than expected (%llu > %llu)",
-                              To.Tell(), ExpectedSize);
+                              To.Tell(), MaximumSize);
+      }
    }
 
    // All done
@@ -984,6 +990,10 @@ bool FtpMethod::Configuration(string Message)
       return false;
    
    TimeOut = _config->FindI("Acquire::Ftp::Timeout",TimeOut);
+
+   // no more active ftp, sorry
+   DropPrivsOrDie();
+
    return true;
 }
                                                                        /*}}}*/
@@ -1054,7 +1064,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
    }
    
    // Open the file
-   Hashes Hash;
+   Hashes Hash(Itm->ExpectedHashes);
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
@@ -1067,7 +1077,7 @@ bool FtpMethod::Fetch(FetchItem *Itm)
       FailFd = Fd.Fd();
       
       bool Missing;
-      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Itm->ExpectedSize) == false)
+      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Itm->MaximumSize,this) == false)
       {
         Fd.Close();
 
@@ -1137,8 +1147,5 @@ int main(int, const char *argv[])
    
    FtpMethod Mth;
 
-   // no more active ftp, sorry
-   Mth.DropPrivsOrDie();
-   
    return Mth.Run();
 }