]> git.saurik.com Git - apt.git/blobdiff - methods/cdrom.cc
Merge remote-tracking branch 'origin/bugfix/bts731738-fancy-progess' into bugfix...
[apt.git] / methods / cdrom.cc
index 7635470134c6d41a9eb68da010b1551b44d7eb03..22d4b9164225e6575363d359be8fb006b1c0e7e5 100644 (file)
@@ -8,12 +8,15 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/acquire-method.h>
 #include <apt-pkg/cdrom.h>
 #include <apt-pkg/cdromutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
 #include <apt-pkg/hashes.h>
 
 #include <sys/stat.h>
@@ -38,7 +41,7 @@ class CDROMMethod : public pkgAcqMethod
    pkgUdevCdromDevices UdevCdroms;
  
    bool IsCorrectCD(URI want, string MountPath, string& NewID);
-   bool AutoDetectAndMount(URI, string &NewID);
+   bool AutoDetectAndMount(const URI, string &NewID);
    virtual bool Fetch(FetchItem *Itm);
    string GetID(string Name);
    virtual void Exit();
@@ -54,7 +57,8 @@ class CDROMMethod : public pkgAcqMethod
 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly |
                                          SendConfig | NeedsCleanup |
                                          Removable), 
-                                          DatabaseLoaded(false), 
+                                          DatabaseLoaded(false),
+                                         Debug(false),
                                           MountedByApt(false)
 {
    UdevCdroms.Dlopen();
@@ -92,7 +96,7 @@ string CDROMMethod::GetID(string Name)
 // CDROMMethod::AutoDetectAndMount                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* Modifies class varaiable CDROM to the mountpoint */
-bool CDROMMethod::AutoDetectAndMount(URI Get, string NewID)
+bool CDROMMethod::AutoDetectAndMount(const URI Get, string &NewID)
 {
    vector<struct CdromDevice> v = UdevCdroms.Scan();
 
@@ -116,23 +120,24 @@ bool CDROMMethod::AutoDetectAndMount(URI Get, string NewID)
       return false;
 
    // check if we have the mount point
-   if (!FileExists("/media/apt"))
-      mkdir("/media/apt", 0755);
+   string AptMountPoint = _config->FindDir("Dir::Media::MountPath");
+   if (!FileExists(AptMountPoint))
+      mkdir(AptMountPoint.c_str(), 0750);
 
    // now try mounting
    for (unsigned int i=0; i < v.size(); i++)
    {
       if (!v[i].Mounted)
       {
-        if(MountCdrom("/media/apt", v[i].DeviceName)) 
+        if(MountCdrom(AptMountPoint, v[i].DeviceName)) 
         {
-           if (IsCorrectCD(Get, "/media/apt", NewID))
+           if (IsCorrectCD(Get, AptMountPoint, NewID))
            {
               MountedByApt = true;
-              CDROM = "/media/apt";
+              CDROM = AptMountPoint;
               return true;
            } else {
-              UnmountCdrom("/media/apt");
+              UnmountCdrom(AptMountPoint);
            }
         }
       }
@@ -218,7 +223,8 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       return true;
    }
 
-   CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+   bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true);
+   CDROM = _config->FindDir("Acquire::cdrom::mount");
    if (Debug)
       clog << "Looking for CDROM at " << CDROM << endl;
 
@@ -228,7 +234,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
    string NewID;
    while (CurrentID.empty() == true)
    {
-      if (CDROM == "apt-udev-auto/") 
+      if (AutoDetect)
         AutoDetectAndMount(Get, NewID);
 
       if(!IsMounted(CDROM))
@@ -262,7 +268,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
 
    Hashes Hash;
    FileFd Fd(Res.Filename, FileFd::ReadOnly);
-   Hash.AddFD(Fd.Fd(), Fd.Size());
+   Hash.AddFD(Fd);
    Res.TakeHashes(Hash);
 
    URIDone(Res);