]> git.saurik.com Git - apt.git/blobdiff - methods/cdrom.cc
Added subprocess to segfault error
[apt.git] / methods / cdrom.cc
index c702e2dc5af565654117cd8a4fbdeadb4f3696f2..e2eddf19e6b56334c889941aaa1b9fc38bfbf3f9 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: cdrom.cc,v 1.11 1999/06/09 23:06:39 jgg Exp $
+// $Id: cdrom.cc,v 1.16 1999/10/18 00:37:36 jgg Exp $
 /* ######################################################################
 
    CDROM URI method for APT
 
 class CDROMMethod : public pkgAcqMethod
 {
-   Configuration Database;
    bool DatabaseLoaded;
+   ::Configuration Database;
    string CurrentID;
+   string CDROM;
+   bool Mounted;
    
    virtual bool Fetch(FetchItem *Itm);
    string GetID(string Name);
+   virtual void Exit();
    
    public:
    
@@ -36,10 +39,21 @@ class CDROMMethod : public pkgAcqMethod
 // ---------------------------------------------------------------------
 /* */
 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly | 
-                                         SendConfig), DatabaseLoaded(false)
+                                         SendConfig | NeedsCleanup), 
+                                          DatabaseLoaded(false), 
+                                          Mounted(false)
 {
 };
                                                                        /*}}}*/
+// CDROMMethod::Exit - Unmount the disc if necessary                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void CDROMMethod::Exit()
+{
+   if (Mounted == true)
+      UnmountCdrom(CDROM);
+}
+                                                                       /*}}}*/
 // CDROMMethod::GetID - Search the database for a matching string      /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -77,6 +91,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
    {
       Res.LastModified = Itm->LastModified;
       Res.IMSHit = true;
+      Res.Filename = File;
       URIDone(Res);
       return true;
    }
@@ -110,11 +125,11 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       return true;
    }
    
-   string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+   CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
    if (CDROM[0] == '.')
       CDROM= SafeGetCWD() + '/' + CDROM;
    string NewID;
-   while (1)
+   while (CurrentID.empty() == true)
    {
       bool Hit = false;
       for (unsigned int Version = 2; Version != 0; Version--)
@@ -148,6 +163,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       }
       
       MountCdrom(CDROM);
+      Mounted = true;
    }
    
    // Found a CD
@@ -156,7 +172,8 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
    if (stat(Res.Filename.c_str(),&Buf) != 0)
       return _error->Error("File not found");
    
-   CurrentID = NewID;
+   if (NewID.empty() == false)
+      CurrentID = NewID;
    Res.LastModified = Buf.st_mtime;
    Res.IMSHit = true;
    Res.Size = Buf.st_size;