]> git.saurik.com Git - apt.git/blobdiff - methods/copy.cc
add sources.list Check-Valid-Until and Valid-Until-{Max,Min} options
[apt.git] / methods / copy.cc
index 8c797ff1fd6a183fd9aa0a59a55697bb241dad84..a8e289df57a71495ecace461ab0e85381f2bdcbd 100644 (file)
 class CopyMethod : public pkgAcqMethod
 {
    virtual bool Fetch(FetchItem *Itm);
-   void CalculateHashes(FetchResult &Res);
+   void CalculateHashes(FetchItem const * const Itm, FetchResult &Res);
    
    public:
    
-   CopyMethod() : pkgAcqMethod("1.0",SingleInstance|SendConfig) {};
+   CopyMethod() : pkgAcqMethod("1.0",SingleInstance | SendConfig) {};
 };
 
-void CopyMethod::CalculateHashes(FetchResult &Res)
+void CopyMethod::CalculateHashes(FetchItem const * const Itm, FetchResult &Res)
 {
-   // For gzip indexes we need to look inside the gzip for the hash
-   // We can not use the extension here as its not used in partial 
-   // on a IMS hit
-   FileFd::OpenMode OpenMode = FileFd::ReadOnly;
+   Hashes Hash(Itm->ExpectedHashes);
+   FileFd::CompressMode CompressMode = FileFd::None;
    if (_config->FindB("Acquire::GzipIndexes", false) == true)
-      OpenMode = FileFd::ReadOnlyGzip;
+      CompressMode = FileFd::Extension;
 
-   Hashes Hash;
-   FileFd Fd(Res.Filename, OpenMode);
+   FileFd Fd(Res.Filename, FileFd::ReadOnly, CompressMode);
    Hash.AddFD(Fd);
    Res.TakeHashes(Hash);
 }
@@ -55,8 +52,8 @@ void CopyMethod::CalculateHashes(FetchResult &Res)
 /* */
 bool CopyMethod::Fetch(FetchItem *Itm)
 {
-   URI Get = Itm->Uri;
-   std::string File = Get.Path;
+   // this ensures that relative paths work in copy
+   std::string File = Itm->Uri.substr(Itm->Uri.find(':')+1);
 
    // Stat the file and send a start message
    struct stat Buf;
@@ -68,17 +65,17 @@ bool CopyMethod::Fetch(FetchItem *Itm)
    Res.Size = Buf.st_size;
    Res.Filename = Itm->DestFile;
    Res.LastModified = Buf.st_mtime;
-   Res.IMSHit = false;      
+   Res.IMSHit = false;
    URIStart(Res);
 
-   // when the files are identical, just compute the hashes
-   if(File == Itm->DestFile)
+   // just calc the hashes if the source and destination are identical
+   if (File == Itm->DestFile)
    {
-      CalculateHashes(Res);
+      CalculateHashes(Itm, Res);
       URIDone(Res);
       return true;
    }
-   
+
    // See if the file exists
    FileFd From(File,FileFd::ReadOnly);
    FileFd To(Itm->DestFile,FileFd::WriteAtomic);
@@ -107,7 +104,7 @@ bool CopyMethod::Fetch(FetchItem *Itm)
    if (utimes(Res.Filename.c_str(), times) != 0)
       return _error->Errno("utimes",_("Failed to set modification time"));
 
-   CalculateHashes(Res);
+   CalculateHashes(Itm, Res);
 
    URIDone(Res);
    return true;
@@ -119,5 +116,6 @@ int main()
    setlocale(LC_ALL, "");
 
    CopyMethod Mth;
+
    return Mth.Run();
 }