瀏覽代碼

CDROMs are unmounted
Author: jgg
Date: 1999-10-18 00:37:35 GMT
CDROMs are unmounted

Arch Librarian 22 年之前
父節點
當前提交
8e5fc8f5be
共有 10 個文件被更改,包括 95 次插入58 次删除
  1. 8 5
      apt-pkg/acquire-method.cc
  2. 4 3
      apt-pkg/acquire-method.h
  3. 6 2
      apt-pkg/acquire-worker.cc
  4. 2 1
      apt-pkg/acquire-worker.h
  5. 43 34
      apt-pkg/acquire.cc
  6. 4 3
      apt-pkg/acquire.h
  7. 2 4
      cmdline/apt-get.cc
  8. 2 1
      debian/changelog
  9. 6 2
      doc/method.sgml
  10. 18 3
      methods/cdrom.cc

+ 8 - 5
apt-pkg/acquire-method.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire-method.cc,v 1.20 1999/08/04 02:39:13 jgg Exp $
+// $Id: acquire-method.cc,v 1.21 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Method
    Acquire Method
@@ -49,6 +49,9 @@ pkgAcqMethod::pkgAcqMethod(const char *Ver,unsigned long Flags)
 
 
    if ((Flags & LocalOnly) == LocalOnly)
    if ((Flags & LocalOnly) == LocalOnly)
       strcat(End,"Local-Only: true\n");
       strcat(End,"Local-Only: true\n");
+
+   if ((Flags & NeedsCleanup) == NeedsCleanup)
+      strcat(End,"Needs-Cleanup: true\n");
    strcat(End,"\n");
    strcat(End,"\n");
 
 
    if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
    if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
@@ -309,10 +312,9 @@ int pkgAcqMethod::Run(bool Single)
       {
       {
 	 if (Single == false)
 	 if (Single == false)
 	    if (WaitFd(STDIN_FILENO) == false)
 	    if (WaitFd(STDIN_FILENO) == false)
-	       return 0;
-      
+	       break;
 	 if (ReadMessages(STDIN_FILENO,Messages) == false)
 	 if (ReadMessages(STDIN_FILENO,Messages) == false)
-	    return 0;
+	    break;
       }
       }
             
             
       // Single mode exits if the message queue is empty
       // Single mode exits if the message queue is empty
@@ -332,7 +334,7 @@ int pkgAcqMethod::Run(bool Single)
       }
       }
 
 
       switch (Number)
       switch (Number)
-      {
+      {	 
 	 case 601:
 	 case 601:
 	 if (Configuration(Message) == false)
 	 if (Configuration(Message) == false)
 	    return 100;
 	    return 100;
@@ -365,6 +367,7 @@ int pkgAcqMethod::Run(bool Single)
       }      
       }      
    }
    }
 
 
+   Exit();
    return 0;
    return 0;
 }
 }
 									/*}}}*/
 									/*}}}*/

+ 4 - 3
apt-pkg/acquire-method.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire-method.h,v 1.11 1999/07/20 05:53:33 jgg Exp $
+// $Id: acquire-method.h,v 1.12 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Method - Method helper class + functions
    Acquire Method - Method helper class + functions
@@ -61,12 +61,13 @@ class pkgAcqMethod
    void URIStart(FetchResult &Res);
    void URIStart(FetchResult &Res);
    void URIDone(FetchResult &Res,FetchResult *Alt = 0);
    void URIDone(FetchResult &Res,FetchResult *Alt = 0);
    bool MediaFail(string Required,string Drive);
    bool MediaFail(string Required,string Drive);
-   
+   void Exit() {};
+
    public:
    public:
 
 
    enum CnfFlags {SingleInstance = (1<<0),
    enum CnfFlags {SingleInstance = (1<<0),
                   Pipeline = (1<<1), SendConfig = (1<<2),
                   Pipeline = (1<<1), SendConfig = (1<<2),
-                  LocalOnly = (1<<3)};
+                  LocalOnly = (1<<3), NeedsCleanup = (1<<4)};
 
 
    void Log(const char *Format,...);
    void Log(const char *Format,...);
    void Status(const char *Format,...);
    void Status(const char *Format,...);

+ 6 - 2
apt-pkg/acquire-worker.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire-worker.cc,v 1.27 1999/08/28 01:49:56 jgg Exp $
+// $Id: acquire-worker.cc,v 1.28 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Worker 
    Acquire Worker 
@@ -86,7 +86,10 @@ pkgAcquire::Worker::~Worker()
    
    
    if (Process > 0)
    if (Process > 0)
    {
    {
-      kill(Process,SIGINT);
+      /* Closing of stdin is the signal to exit and die when the process
+         indicates it needs cleanup */
+      if (Config->NeedsCleanup == false)
+	 kill(Process,SIGINT);
       ExecWait(Process,Access.c_str(),true);
       ExecWait(Process,Access.c_str(),true);
    }   
    }   
 }
 }
@@ -323,6 +326,7 @@ bool pkgAcquire::Worker::Capabilities(string Message)
    Config->Pipeline = StringToBool(LookupTag(Message,"Pipeline"),false);
    Config->Pipeline = StringToBool(LookupTag(Message,"Pipeline"),false);
    Config->SendConfig = StringToBool(LookupTag(Message,"Send-Config"),false);
    Config->SendConfig = StringToBool(LookupTag(Message,"Send-Config"),false);
    Config->LocalOnly = StringToBool(LookupTag(Message,"Local-Only"),false);
    Config->LocalOnly = StringToBool(LookupTag(Message,"Local-Only"),false);
+   Config->NeedsCleanup = StringToBool(LookupTag(Message,"Needs-Cleanup"),false);
 
 
    // Some debug text
    // Some debug text
    if (Debug == true)
    if (Debug == true)

+ 2 - 1
apt-pkg/acquire-worker.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire-worker.h,v 1.10 1999/05/23 06:47:43 jgg Exp $
+// $Id: acquire-worker.h,v 1.11 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Worker - Worker process manager
    Acquire Worker - Worker process manager
@@ -79,6 +79,7 @@ class pkgAcquire::Worker
    bool QueueItem(pkgAcquire::Queue::QItem *Item);
    bool QueueItem(pkgAcquire::Queue::QItem *Item);
    bool Start();
    bool Start();
    void Pulse();
    void Pulse();
+   inline const MethodConfig *GetConf() const {return Config;};
    
    
    Worker(Queue *OwnerQ,MethodConfig *Config,pkgAcquireStatus *Log);
    Worker(Queue *OwnerQ,MethodConfig *Config,pkgAcquireStatus *Log);
    Worker(MethodConfig *Config);
    Worker(MethodConfig *Config);

+ 43 - 34
apt-pkg/acquire.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire.cc,v 1.39 1999/10/16 19:53:18 jgg Exp $
+// $Id: acquire.cc,v 1.40 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire - File Acquiration
    Acquire - File Acquiration
@@ -63,7 +63,7 @@ pkgAcquire::~pkgAcquire()
    Shutdown();
    Shutdown();
 }
 }
 									/*}}}*/
 									/*}}}*/
-// pkgAcquire::Shutdown - Clean out the acquire object			/*{{{*/
+// Acquire::Shutdown - Clean out the acquire object			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 void pkgAcquire::Shutdown()
 void pkgAcquire::Shutdown()
@@ -345,11 +345,11 @@ pkgAcquire::RunResult pkgAcquire::Run()
    // Shut down the acquire bits
    // Shut down the acquire bits
    Running = false;
    Running = false;
    for (Queue *I = Queues; I != 0; I = I->Next)
    for (Queue *I = Queues; I != 0; I = I->Next)
-      I->Shutdown();
+      I->Shutdown(false);
 
 
    // Shut down the items
    // Shut down the items
    for (Item **I = Items.begin(); I != Items.end(); I++)
    for (Item **I = Items.begin(); I != Items.end(); I++)
-      (*I)->Finished();
+      (*I)->Finished(); 
    
    
    if (_error->PendingError())
    if (_error->PendingError())
       return Failed;
       return Failed;
@@ -453,7 +453,7 @@ unsigned long pkgAcquire::PartialPresent()
    return Total;
    return Total;
 }
 }
 									/*}}}*/
 									/*}}}*/
-// pkgAcquire::UriBegin - Start iterator for the uri list		/*{{{*/
+// Acquire::UriBegin - Start iterator for the uri list			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 pkgAcquire::UriIterator pkgAcquire::UriBegin()
 pkgAcquire::UriIterator pkgAcquire::UriBegin()
@@ -461,7 +461,7 @@ pkgAcquire::UriIterator pkgAcquire::UriBegin()
    return UriIterator(Queues);
    return UriIterator(Queues);
 }
 }
 									/*}}}*/
 									/*}}}*/
-// pkgAcquire::UriEnd - End iterator for the uri list			/*{{{*/
+// Acquire::UriEnd - End iterator for the uri list			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 pkgAcquire::UriIterator pkgAcquire::UriEnd()
 pkgAcquire::UriIterator pkgAcquire::UriEnd()
@@ -501,7 +501,7 @@ pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name),
 /* */
 /* */
 pkgAcquire::Queue::~Queue()
 pkgAcquire::Queue::~Queue()
 {
 {
-   Shutdown();
+   Shutdown(true);
    
    
    while (Items != 0)
    while (Items != 0)
    {
    {
@@ -560,44 +560,53 @@ bool pkgAcquire::Queue::Dequeue(Item *Owner)
 									/*}}}*/
 									/*}}}*/
 // Queue::Startup - Start the worker processes				/*{{{*/
 // Queue::Startup - Start the worker processes				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
+/* It is possible for this to be called with a pre-existing set of
+   workers. */
 bool pkgAcquire::Queue::Startup()
 bool pkgAcquire::Queue::Startup()
 {
 {
-   Shutdown();
-   
-   URI U(Name);
-   pkgAcquire::MethodConfig *Cnf = Owner->GetConfig(U.Access);
-   if (Cnf == 0)
-      return false;
-   
-   Workers = new Worker(this,Cnf,Owner->Log);
-   Owner->Add(Workers);
-   if (Workers->Start() == false)
-      return false;
-   
-   /* When pipelining we commit 10 items. This needs to change when we
-      added other source retry to have cycle maintain a pipeline depth
-      on its own. */
-   if (Cnf->Pipeline == true)
-      MaxPipeDepth = 10;
-   else
-      MaxPipeDepth = 1;
+   if (Workers == 0)
+   {
+      URI U(Name);
+      pkgAcquire::MethodConfig *Cnf = Owner->GetConfig(U.Access);
+      if (Cnf == 0)
+	 return false;
+      
+      Workers = new Worker(this,Cnf,Owner->Log);
+      Owner->Add(Workers);
+      if (Workers->Start() == false)
+	 return false;
+      
+      /* When pipelining we commit 10 items. This needs to change when we
+         added other source retry to have cycle maintain a pipeline depth
+         on its own. */
+      if (Cnf->Pipeline == true)
+	 MaxPipeDepth = 10;
+      else
+	 MaxPipeDepth = 1;
+   }
    
    
    return Cycle();
    return Cycle();
 }
 }
 									/*}}}*/
 									/*}}}*/
 // Queue::Shutdown - Shutdown the worker processes			/*{{{*/
 // Queue::Shutdown - Shutdown the worker processes			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
-/* */
-bool pkgAcquire::Queue::Shutdown()
+/* If final is true then all workers are eliminated, otherwise only workers
+   that do not need cleanup are removed */
+bool pkgAcquire::Queue::Shutdown(bool Final)
 {
 {
    // Delete all of the workers
    // Delete all of the workers
-   while (Workers != 0)
+   pkgAcquire::Worker **Cur = &Workers;
+   while (*Cur != 0)
    {
    {
-      pkgAcquire::Worker *Jnk = Workers;
-      Workers = Workers->NextQueue;
-      Owner->Remove(Jnk);
-      delete Jnk;
+      pkgAcquire::Worker *Jnk = *Cur;
+      if (Final == true || Jnk->GetConf()->NeedsCleanup == false)
+      {
+	 *Cur = Jnk->NextQueue;
+	 Owner->Remove(Jnk);
+	 delete Jnk;
+      }
+      else
+	 Cur = &(*Cur)->NextQueue;      
    }
    }
    
    
    return true;
    return true;

+ 4 - 3
apt-pkg/acquire.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: acquire.h,v 1.24 1999/07/20 05:53:33 jgg Exp $
+// $Id: acquire.h,v 1.25 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire - File Acquiration
    Acquire - File Acquiration
@@ -175,7 +175,7 @@ class pkgAcquire::Queue
    bool ItemDone(QItem *Itm);
    bool ItemDone(QItem *Itm);
    
    
    bool Startup();
    bool Startup();
-   bool Shutdown();
+   bool Shutdown(bool Final);
    bool Cycle();
    bool Cycle();
    void Bump();
    void Bump();
    
    
@@ -229,7 +229,8 @@ struct pkgAcquire::MethodConfig
    bool Pipeline;
    bool Pipeline;
    bool SendConfig;
    bool SendConfig;
    bool LocalOnly;
    bool LocalOnly;
-      
+   bool NeedsCleanup;
+   
    MethodConfig();
    MethodConfig();
 };
 };
 
 

+ 2 - 4
cmdline/apt-get.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: apt-get.cc,v 1.79 1999/10/17 07:49:41 jgg Exp $
+// $Id: apt-get.cc,v 1.80 1999/10/18 00:37:35 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    apt-get - Cover for dpkg
    apt-get - Cover for dpkg
@@ -660,7 +660,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,bool Saftey =
    while (1)
    while (1)
    {
    {
       if (_config->FindB("APT::Get::No-Download",false) == false)
       if (_config->FindB("APT::Get::No-Download",false) == false)
-	 if( Fetcher.Run() == pkgAcquire::Failed)
+	 if (Fetcher.Run() == pkgAcquire::Failed)
 	    return false;
 	    return false;
       
       
       // Print out errors
       // Print out errors
@@ -672,8 +672,6 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,bool Saftey =
 	     (*I)->Complete == true)
 	     (*I)->Complete == true)
 	    continue;
 	    continue;
 	 
 	 
-	 (*I)->Finished();
-	 
 	 if ((*I)->Status == pkgAcquire::Item::StatIdle)
 	 if ((*I)->Status == pkgAcquire::Item::StatIdle)
 	 {
 	 {
 	    Transient = true;
 	    Transient = true;

+ 2 - 1
debian/changelog

@@ -2,7 +2,7 @@ apt (0.3.13.1) unstable; urgency=low
 
 
   * Fix Perl or group pre-depends thing Closes: #46091, #46096, #46233, #45901
   * Fix Perl or group pre-depends thing Closes: #46091, #46096, #46233, #45901
   * Fix handling of dpkg's conversions from < -> <= Closes: #46094, #47088
   * Fix handling of dpkg's conversions from < -> <= Closes: #46094, #47088
-  * Make unparsable priorities non-fatal Closes: #46266, #46267, #46293, #46298  
+  * Make unparsable priorities non-fatal Closes: #46266, #46267, #46293, #46298
   * Fix handling of '/' for the dist name. Closes: #43830, #45640, #45692
   * Fix handling of '/' for the dist name. Closes: #43830, #45640, #45692
   * Fixed 'Method gave a blank filename' error from IMS queries onto CDs.
   * Fixed 'Method gave a blank filename' error from IMS queries onto CDs.
     Closes: #45034, #45695, #46537
     Closes: #45034, #45695, #46537
@@ -16,6 +16,7 @@ apt (0.3.13.1) unstable; urgency=low
   * Tweaked Dselect 'update' script to re-gen the avail file even in the
   * Tweaked Dselect 'update' script to re-gen the avail file even in the
     event of a failure Closes: #47112
     event of a failure Closes: #47112
   * Retries for source archives too Closes: #47529
   * Retries for source archives too Closes: #47529
+  * Unmounts CDROMs iff it mounted them Closes: #45299
   
   
  -- Jason Gunthorpe <jgg@debian.org>  Fri,  3 Sep 1999 09:04:28 -0700
  -- Jason Gunthorpe <jgg@debian.org>  Fri,  3 Sep 1999 09:04:28 -0700
  
  

+ 6 - 2
doc/method.sgml

@@ -4,7 +4,7 @@
 <title>APT Method Interface </title>
 <title>APT Method Interface </title>
 
 
 <author>Jason Gunthorpe <email>jgg@debian.org</email></author>
 <author>Jason Gunthorpe <email>jgg@debian.org</email></author>
-<version>$Id: method.sgml,v 1.6 1998/12/14 04:00:34 jgg Exp $</version>
+<version>$Id: method.sgml,v 1.7 1999/10/18 00:37:36 jgg Exp $</version>
 
 
 <abstract>
 <abstract>
 This document describes the interface that APT uses to the archive
 This document describes the interface that APT uses to the archive
@@ -219,6 +219,9 @@ the ones it wants.
 <tag>Pipeline<item>The method is capable of pipelining.
 <tag>Pipeline<item>The method is capable of pipelining.
 <tag>Local<item>The method only returns Filename: feilds.
 <tag>Local<item>The method only returns Filename: feilds.
 <tag>Send-Config<item>Send configuration to the method.
 <tag>Send-Config<item>Send configuration to the method.
+<tag>Needs-Cleanup<item>The process is kept around while the files it returned
+are being used. This is primarily intended for CDROM and File URIs that need
+to unmount filesystems.
 <tag>Version<item>Version string for the method
 <tag>Version<item>Version string for the method
 </taglist>
 </taglist>
 
 
@@ -229,7 +232,8 @@ This is a list of which headers each status code can use
 Displays the capabilities of the method. Methods should set the
 Displays the capabilities of the method. Methods should set the
 pipeline bit if their underlying protocol supports pipeling. The
 pipeline bit if their underlying protocol supports pipeling. The
 only known method that does support pipelining is http.
 only known method that does support pipelining is http.
-Fields: Version, Single-Instance, Pre-Scan, Pipeline, Send-Config
+Fields: Version, Single-Instance, Pre-Scan, Pipeline, Send-Config, 
+Needs-Cleanup
 
 
 <tag>101 Log<item>
 <tag>101 Log<item>
 A log message may be printed to the screen if debugging is enabled. This
 A log message may be printed to the screen if debugging is enabled. This

+ 18 - 3
methods/cdrom.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: cdrom.cc,v 1.15 1999/10/02 04:14:54 jgg Exp $
+// $Id: cdrom.cc,v 1.16 1999/10/18 00:37:36 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    CDROM URI method for APT
    CDROM URI method for APT
@@ -23,9 +23,12 @@ class CDROMMethod : public pkgAcqMethod
    bool DatabaseLoaded;
    bool DatabaseLoaded;
    ::Configuration Database;
    ::Configuration Database;
    string CurrentID;
    string CurrentID;
+   string CDROM;
+   bool Mounted;
    
    
    virtual bool Fetch(FetchItem *Itm);
    virtual bool Fetch(FetchItem *Itm);
    string GetID(string Name);
    string GetID(string Name);
+   virtual void Exit();
    
    
    public:
    public:
    
    
@@ -36,10 +39,21 @@ class CDROMMethod : public pkgAcqMethod
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
 CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly | 
 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	/*{{{*/
 // CDROMMethod::GetID - Search the database for a matching string	/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
@@ -111,7 +125,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       return true;
       return true;
    }
    }
    
    
-   string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+   CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
    if (CDROM[0] == '.')
    if (CDROM[0] == '.')
       CDROM= SafeGetCWD() + '/' + CDROM;
       CDROM= SafeGetCWD() + '/' + CDROM;
    string NewID;
    string NewID;
@@ -149,6 +163,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
       }
       }
       
       
       MountCdrom(CDROM);
       MountCdrom(CDROM);
+      Mounted = true;
    }
    }
    
    
    // Found a CD
    // Found a CD