CDROM method
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:51:49 +0000 (16:51 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:51:49 +0000 (16:51 +0000)
Author: jgg
Date: 1998-12-03 07:29:16 GMT
CDROM method

apt-pkg/acquire-method.cc
apt-pkg/acquire-method.h
apt-pkg/contrib/strutl.cc
doc/Bugs
methods/cdrom.cc [new file with mode: 0644]
methods/makefile
test/scratch.cc
test/versions.lst

index bf2de54..7c3fdec 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-method.cc,v 1.9 1998/11/29 01:24:15 jgg Exp $
+// $Id: acquire-method.cc,v 1.10 1998/12/03 07:29:16 jgg Exp $
 /* ######################################################################
 
    Acquire Method
@@ -185,6 +185,59 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
    delete Tmp;
 }
                                                                        /*}}}*/
+// AcqMethod::MediaFail - Syncronous request for new media             /*{{{*/
+// ---------------------------------------------------------------------
+/* This sends a 403 Media Failure message to the APT and waits for it
+   to be ackd */
+void pkgAcqMethod::MediaFail(string Required,string Drive)
+{
+   char S[1024];
+   snprintf(S,sizeof(S),"403 Media Failure\nMedia: %s\nDrive: %s\n\n",
+           Required.c_str(),Drive.c_str());
+
+   if (write(STDOUT_FILENO,S,strlen(S)) != (signed)strlen(S))
+      exit(100);
+   
+   vector<string> MyMessages;
+   
+   /* Here we read messages until we find a 603, each non 603 message is
+      appended to the main message list for later processing */
+   while (1)
+   {
+      if (WaitFd(STDIN_FILENO) == false)
+        exit(0);
+      
+      if (ReadMessages(STDIN_FILENO,MyMessages) == false)
+        exit(0);
+      
+      string Message = MyMessages.front();
+      MyMessages.erase(MyMessages.begin());
+      
+      // Fetch the message number
+      char *End;
+      int Number = strtol(Message.c_str(),&End,10);
+      if (End == Message.c_str())
+      {         
+        cerr << "Malformed message!" << endl;
+        exit(100);
+      }
+
+      // Change ack
+      if (Number == 603)
+      {
+        while (Message.empty() == false)
+        {
+           Messages.push_back(MyMessages.front());
+           MyMessages.erase(MyMessages.begin());
+        }
+        
+        return;
+      }
+      
+      Messages.push_back(Message);
+   }   
+}
+                                                                       /*}}}*/
 // AcqMethod::Configuration - Handle the configuration message         /*{{{*/
 // ---------------------------------------------------------------------
 /* This parses each configuration entry and puts it into the _config 
index 9e4ac65..08c8826 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire-method.h,v 1.4 1998/11/29 01:24:16 jgg Exp $
+// $Id: acquire-method.h,v 1.5 1998/12/03 07:29:17 jgg Exp $
 /* ######################################################################
 
    Acquire Method - Method helper class + functions
@@ -58,7 +58,8 @@ class pkgAcqMethod
    void Fail(string Why, bool Transient = false);
    void URIStart(FetchResult &Res);
    void URIDone(FetchResult &Res,FetchResult *Alt = 0);
-                
+   void MediaFail(string Required,string Drive);
+   
    public:
 
    enum CnfFlags {SingleInstance = (1<<0),
index d5f765d..273118e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: strutl.cc,v 1.13 1998/11/05 07:21:44 jgg Exp $
+// $Id: strutl.cc,v 1.14 1998/12/03 07:29:18 jgg Exp $
 /* ######################################################################
 
    String Util - Some usefull string functions.
@@ -630,7 +630,7 @@ void URI::CopyFrom(string U)
       SingleSlash += 3;
    for (; SingleSlash < U.end() && *SingleSlash != '/'; SingleSlash++);
    if (SingleSlash > U.end())
-        SingleSlash = U.end();
+      SingleSlash = U.end();
 
    // We can now write the access and path specifiers
    Access = string(U,0,FirstColon - U.begin());
@@ -640,7 +640,10 @@ void URI::CopyFrom(string U)
       Path = "/";
 
    // Now we attempt to locate a user:pass@host fragment
-   FirstColon += 3;
+   if (U[1] == '/' && U[2] == '/')
+      FirstColon += 3;
+   else
+      FirstColon += 1;
    if (FirstColon >= U.end())
       return;
    
index 8513de5..89a5a3f 100644 (file)
--- a/doc/Bugs
+++ b/doc/Bugs
 #30027: apt: version comparison bug
  Summary: Version compare differs from dpkg
  Status: Fixed in all CVS versions.
-
+#30260: apt: wishlist: do not return to main menu without prompting for return
+ Summary: Wants to prompt after dselect update
+ Status: Fixed in v3, use dselect::promptafterupdate "true";
 -- Silly things
 #26592: apt: Problems with ftpd in SunOS 5.6
 #29903: apt-get insists onto sending a SIZE command
diff --git a/methods/cdrom.cc b/methods/cdrom.cc
new file mode 100644 (file)
index 0000000..0d1e8f0
--- /dev/null
@@ -0,0 +1,144 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+// $Id: cdrom.cc,v 1.1 1998/12/03 07:29:21 jgg Exp $
+/* ######################################################################
+
+   CDROM URI method for APT
+   
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/acquire-method.h>
+#include <apt-pkg/cdromutl.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+
+#include <sys/stat.h>
+#include <unistd.h>
+                                                                       /*}}}*/
+
+class CDROMMethod : public pkgAcqMethod
+{
+   Configuration Database;
+   string CurrentID;
+   
+   virtual bool Fetch(FetchItem *Itm);
+   string GetID(string Name);
+   
+   public:
+   
+   CDROMMethod();
+};
+
+// CDROMMethod::CDROMethod - Constructor                               /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+CDROMMethod::CDROMMethod() : pkgAcqMethod("1.0",SingleInstance | LocalOnly) 
+{
+   // Read the database
+   string DFile = _config->FindFile("Dir::State::cdroms");
+   if (FileExists(DFile) == true)
+   {
+      if (ReadConfigFile(Database,DFile) == false)
+      {
+        _error->Error("Unable to read the cdrom database %s",
+                      DFile.c_str());
+        Fail();
+      }   
+   }      
+};
+                                                                       /*}}}*/
+// CDROMMethod::GetID - Get the ID hash for                                                                    /*{{{*/
+// ---------------------------------------------------------------------
+/* We search the configuration space for the name and then return the ID
+   tag associated with it. */
+string CDROMMethod::GetID(string Name)
+{
+   const Configuration::Item *Top = Database.Tree(0);
+   for (; Top != 0;)
+   {
+      if (Top->Value == Name)
+        return Top->Tag;
+
+      Top = Top->Next;
+   }   
+   
+   return string();
+}
+                                                                       /*}}}*/
+// CDROMMethod::Fetch - Fetch a file                                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool CDROMMethod::Fetch(FetchItem *Itm)
+{
+   URI Get = Itm->Uri;
+   string File = Get.Path;
+   FetchResult Res;
+   
+   /* All IMS queries are returned as a hit, CDROMs are readonly so 
+      time stamps never change */
+   if (Itm->LastModified != 0)
+   {
+      Res.LastModified = Itm->LastModified;
+      Res.IMSHit = true;
+      URIDone(Res);
+      return true;
+   }
+   
+   string ID = GetID(Get.Host);
+   
+   // All non IMS queries for package files fail.
+   if (Itm->IndexFile == true || ID.empty() == false)
+   {
+      Fail("Please use apt-cdrom to make this CD recognized by APT."
+          " apt-get update cannot be used to add new CDs");
+      return true;
+   }
+
+   // We already have a CD inserted, but it is the wrong one
+   if (CurrentID.empty() == false && ID != CurrentID)
+   {
+      Fail("Wrong CD",true);
+      return true;
+   }
+   
+   string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+   string NewID;
+   while (1)
+   {
+      if (IdentCdrom(CDROM,NewID) == false)
+        return false;
+   
+      // A hit
+      if (NewID == ID)
+        break;
+      
+      UnmountCdrom(CDROM);
+      MediaFail(Get.Host,CDROM);
+      MountCdrom(CDROM);
+   }
+   
+   // ID matches
+   if (NewID == ID)
+   {
+      Res.Filename = CDROM + File;
+      if (FileExists(Res.Filename) == false)
+        return _error->Error("File not found");
+    
+      CurrentID = ID;
+      Res.LastModified = Itm->LastModified;
+      Res.IMSHit = true;
+      URIDone(Res);
+      return true;
+   }
+   
+   return _error->Error("CDROM not found");
+}
+                                                                       /*}}}*/
+
+int main()
+{
+   CDROMMethod Mth;
+   return Mth.Run();
+}
index b05356b..2940b89 100644 (file)
@@ -24,6 +24,12 @@ SLIBS = -lapt-pkg
 SOURCE = gzip.cc
 include $(PROGRAM_H)
 
+# The cdrom method
+PROGRAM=cdrom
+SLIBS = -lapt-pkg 
+SOURCE = cdrom.cc
+include $(PROGRAM_H)
+
 # The http method
 PROGRAM=http
 SLIBS = -lapt-pkg 
index 74c9767..6783f37 100644 (file)
@@ -201,7 +201,7 @@ int main(int argc,char *argv[])
 {
    signal(SIGPIPE,SIG_IGN);
 
-/*   URI Foo(argv[1]);
+   URI Foo(argv[1]);
    cout << Foo.Access << '\'' << endl;
    cout << Foo.Host << '\'' << endl;
    cout << Foo.Path << '\'' << endl;
@@ -209,7 +209,7 @@ int main(int argc,char *argv[])
    cout << Foo.Password << '\'' << endl;
    cout << Foo.Port << endl;
    
-   return 0;*/
+   return 0;
 
    pkgInitialize(*_config);
    
index d5d343b..5f53f8b 100644 (file)
@@ -6,6 +6,8 @@
 #  0 means that ver1 = ver2
 7.6p2-4 7.6-0 1
 1.0.3-3 1.0-1 1
+1.3 1.2.2-2 1
+1.3 1.2.2 1
 
 # Important attributes
 - . -1