]> git.saurik.com Git - apt.git/blobdiff - methods/cdrom.cc
lots of cppcheck fixes
[apt.git] / methods / cdrom.cc
index 9802eb46ceb4ffd0ca7b9c33229216fde56e499b..ae699dfc33b5479648b251446d374231a68c12bc 100644 (file)
@@ -37,8 +37,8 @@ class CDROMMethod : public pkgAcqMethod
    bool MountedByApt;
    pkgUdevCdromDevices UdevCdroms;
  
-   bool IsCorrectCD(URI want, string MountPath);
-   bool AutoDetectAndMount(URI);
+   bool IsCorrectCD(URI want, string MountPath, string& NewID);
+   bool AutoDetectAndMount(const URI, string &NewID);
    virtual bool Fetch(FetchItem *Itm);
    string GetID(string Name);
    virtual void Exit();
@@ -54,7 +54,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 +93,7 @@ string CDROMMethod::GetID(string Name)
 // CDROMMethod::AutoDetectAndMount                                      /*{{{*/
 // ---------------------------------------------------------------------
 /* Modifies class varaiable CDROM to the mountpoint */
-bool CDROMMethod::AutoDetectAndMount(URI Get)
+bool CDROMMethod::AutoDetectAndMount(const URI Get, string &NewID)
 {
    vector<struct CdromDevice> v = UdevCdroms.Scan();
 
@@ -103,7 +104,7 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
       {
         if (Debug)
            clog << "Checking mounted cdrom device " << v[i].DeviceName << endl;
-        if (IsCorrectCD(Get, v[i].MountPath))
+        if (IsCorrectCD(Get, v[i].MountPath, NewID))
         {
            CDROM = v[i].MountPath;
            return true;
@@ -116,23 +117,24 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
       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"))
+           if (IsCorrectCD(Get, AptMountPoint, NewID))
            {
               MountedByApt = true;
-              CDROM = "/media/apt";
+              CDROM = AptMountPoint;
               return true;
            } else {
-              UnmountCdrom("/media/apt");
+              UnmountCdrom(AptMountPoint);
            }
         }
       }
@@ -144,10 +146,8 @@ bool CDROMMethod::AutoDetectAndMount(URI Get)
 // CDROMMethod::IsCorrectCD                                             /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool CDROMMethod::IsCorrectCD(URI want, string MountPath)
+bool CDROMMethod::IsCorrectCD(URI want, string MountPath, string& NewID)
 {
-   string NewID;
-
    for (unsigned int Version = 2; Version != 0; Version--)
    {
       if (IdentCdrom(MountPath,NewID,Version) == false)
@@ -220,23 +220,24 @@ 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;
 
    if (CDROM[0] == '.')
       CDROM= SafeGetCWD() + '/' + CDROM;
-   string NewID;
 
+   string NewID;
    while (CurrentID.empty() == true)
    {
-      if (CDROM == "apt-udev-auto/") 
-        AutoDetectAndMount(Get);
+      if (AutoDetect)
+        AutoDetectAndMount(Get, NewID);
 
       if(!IsMounted(CDROM))
         MountedByApt = MountCdrom(CDROM);
       
-      if (IsCorrectCD(Get, CDROM))
+      if (IsCorrectCD(Get, CDROM, NewID))
         break;
         
       // I suppose this should prompt somehow?