]> git.saurik.com Git - apt.git/blobdiff - methods/cdrom.cc
Fix backward compatiblity of the new pkgAcquireMethod::DropPrivsOrDie()
[apt.git] / methods / cdrom.cc
index b0f1a1551b0c179294ed2a492ca9f09fb7340162..74e2ecc6b632d138e464cb88951449385c6478a9 100644 (file)
@@ -8,17 +8,20 @@
    ##################################################################### */
                                                                        /*}}}*/
 // 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 <string>
+#include <vector>
 #include <sys/stat.h>
-#include <unistd.h>
-#include <dlfcn.h>
 
 #include <iostream>
 #include <apti18n.h>
@@ -54,11 +57,12 @@ class CDROMMethod : public pkgAcqMethod
 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly |
                                          SendConfig | NeedsCleanup |
                                          Removable), 
-                                          DatabaseLoaded(false), 
+                                          DatabaseLoaded(false),
+                                         Debug(false),
                                           MountedByApt(false)
 {
    UdevCdroms.Dlopen();
-};
+}
                                                                        /*}}}*/
 // CDROMMethod::Exit - Unmount the disc if necessary                   /*{{{*/
 // ---------------------------------------------------------------------
@@ -116,23 +120,24 @@ bool CDROMMethod::AutoDetectAndMount(const 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);