]> git.saurik.com Git - apt.git/blobdiff - methods/copy.cc
debian/apt.postinst: chown _apt:root /etc/apt/auth.conf
[apt.git] / methods / copy.cc
index 8c797ff1fd6a183fd9aa0a59a55697bb241dad84..a23c0316c4717568950cacf3aebee238c4fdde30 100644 (file)
@@ -32,20 +32,17 @@ class CopyMethod : public pkgAcqMethod
    
    public:
    
-   CopyMethod() : pkgAcqMethod("1.0",SingleInstance|SendConfig) {};
+   CopyMethod() : pkgAcqMethod("1.0",SingleInstance | SendConfig) {};
 };
 
 void CopyMethod::CalculateHashes(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;
+   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;
@@ -79,6 +76,14 @@ bool CopyMethod::Fetch(FetchItem *Itm)
       return true;
    }
    
+   // just calc the hashes if the source and destination are identical
+   if (File == Itm->DestFile)
+   {
+      CalculateHashes(Res);
+      URIDone(Res);
+      return true;
+   }
+
    // See if the file exists
    FileFd From(File,FileFd::ReadOnly);
    FileFd To(Itm->DestFile,FileFd::WriteAtomic);
@@ -119,5 +124,6 @@ int main()
    setlocale(LC_ALL, "");
 
    CopyMethod Mth;
+
    return Mth.Run();
 }