Explorar o código

Minor cleanups, fix for checksum lowercase bug
Author: jgg
Date: 1999-07-26 17:46:07 GMT
Minor cleanups, fix for checksum lowercase bug

Arch Librarian %!s(int64=22) %!d(string=hai) anos
pai
achega
ddc1d8d08e

+ 3 - 6
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.22 1999/05/23 06:47:43 jgg Exp $
+// $Id: acquire-worker.cc,v 1.23 1999/07/26 17:46:07 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    Acquire Worker 
    Acquire Worker 
@@ -26,7 +26,6 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <signal.h>
-#include <wait.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <errno.h>
 #include <errno.h>
 									/*}}}*/
 									/*}}}*/
@@ -84,8 +83,7 @@ pkgAcquire::Worker::~Worker()
    if (Process > 0)
    if (Process > 0)
    {
    {
       kill(Process,SIGINT);
       kill(Process,SIGINT);
-      if (waitpid(Process,0,0) != Process)
-	 _error->Warning("I waited but nothing was there!");
+      ExecWait(Process,Access.c_str(),true);
    }   
    }   
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -471,8 +469,7 @@ bool pkgAcquire::Worker::MethodFailure()
 {
 {
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
    
    
-   if (waitpid(Process,0,0) != Process)
-      _error->Warning("I waited but nothing was there!");
+   ExecWait(Process,Access.c_str(),true);
    Process = -1;
    Process = -1;
    close(InFd);
    close(InFd);
    close(OutFd);
    close(OutFd);

+ 3 - 25
apt-pkg/contrib/cdromutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: cdromutl.cc,v 1.7 1999/07/02 22:21:01 jgg Exp $
+// $Id: cdromutl.cc,v 1.8 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    CDROM Utilities - Some functions to manipulate CDROM mounts.
    CDROM Utilities - Some functions to manipulate CDROM mounts.
@@ -93,18 +93,7 @@ bool UnmountCdrom(string Path)
    }
    }
 
 
    // Wait for mount
    // Wait for mount
-   int Status = 0;
-   while (waitpid(Child,&Status,0) != Child)
-   {
-      if (errno == EINTR)
-	 continue;
-      return _error->Errno("waitpid","Couldn't wait for subprocess");
-   }
-   
-   // Check for an error code.
-   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
-      return false;
-   return true;
+   return ExecWait(Child,"mount",true);
 }
 }
 									/*}}}*/
 									/*}}}*/
 // MountCdrom - Mount a cdrom						/*{{{*/
 // MountCdrom - Mount a cdrom						/*{{{*/
@@ -142,18 +131,7 @@ bool MountCdrom(string Path)
    }
    }
 
 
    // Wait for mount
    // Wait for mount
-   int Status = 0;
-   while (waitpid(Child,&Status,0) != Child)
-   {
-      if (errno == EINTR)
-	 continue;
-      return _error->Errno("waitpid","Couldn't wait for subprocess");
-   }
-   
-   // Check for an error code.
-   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
-      return false;
-   return true;
+   return ExecWait(Child,"mount",true);
 }
 }
 									/*}}}*/
 									/*}}}*/
 // IdentCdrom - Generate a unique string for this CD			/*{{{*/
 // IdentCdrom - Generate a unique string for this CD			/*{{{*/

+ 51 - 2
apt-pkg/contrib/fileutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.cc,v 1.29 1999/07/20 05:53:33 jgg Exp $
+// $Id: fileutl.cc,v 1.30 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/time.h>
 #include <signal.h>
 #include <signal.h>
+#include <wait.h>
 #include <errno.h>
 #include <errno.h>
 									/*}}}*/
 									/*}}}*/
 
 
@@ -249,6 +250,47 @@ int ExecFork()
    return Process;
    return Process;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// ExecWait - Fancy waitpid						/*{{{*/
+// ---------------------------------------------------------------------
+/* Waits for the given sub process. If Reap is set the no errors are 
+   generated. Otherwise a failed subprocess will generate a proper descriptive
+   message */
+bool ExecWait(int Pid,const char *Name,bool Reap)
+{
+   if (Pid <= 1)
+      return true;
+   
+   // Wait and collect the error code
+   int Status;
+   while (waitpid(Pid,&Status,0) != Pid)
+   {
+      if (errno == EINTR)
+	 continue;
+
+      if (Reap == true)
+	 return false;
+      
+      return _error->Error("Waited, for %s but it wasn't there",Name);
+   }
+
+   
+   // Check for an error code.
+   if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
+   {
+      if (Reap == true)
+	 return false;
+      if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
+	 return _error->Error("Sub-process %s recieved a segmentation fault.",Name);
+
+      if (WIFEXITED(Status) != 0)
+	 return _error->Error("Sub-process %s returned an error code (%u)",Name,WEXITSTATUS(Status));
+      
+      return _error->Error("Sub-process %s exited unexpectedly",Name);
+   }      
+   
+   return true;
+}
+									/*}}}*/
 
 
 // FileFd::Open - Open a file						/*{{{*/
 // FileFd::Open - Open a file						/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
@@ -302,7 +344,7 @@ FileFd::~FileFd()
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* We are carefull to handle interruption by a signal while reading 
 /* We are carefull to handle interruption by a signal while reading 
    gracefully. */
    gracefully. */
-bool FileFd::Read(void *To,unsigned long Size)
+bool FileFd::Read(void *To,unsigned long Size,bool AllowEof)
 {
 {
    int Res;
    int Res;
    errno = 0;
    errno = 0;
@@ -325,6 +367,13 @@ bool FileFd::Read(void *To,unsigned long Size)
    if (Size == 0)
    if (Size == 0)
       return true;
       return true;
    
    
+   // Eof handling
+   if (AllowEof == true)
+   {
+      Flags |= HitEof;
+      return true;
+   }
+   
    Flags |= Fail;
    Flags |= Fail;
    return _error->Error("read, still have %u to read but none left",Size);
    return _error->Error("read, still have %u to read but none left",Size);
 }
 }

+ 6 - 3
apt-pkg/contrib/fileutl.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: fileutl.h,v 1.20 1999/07/20 05:53:33 jgg Exp $
+// $Id: fileutl.h,v 1.21 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    File Utilities
    File Utilities
@@ -32,14 +32,15 @@ class FileFd
    protected:
    protected:
    int iFd;
    int iFd;
  
  
-   enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2)};
+   enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2),
+                    HitEof = (1<<3)};
    unsigned long Flags;
    unsigned long Flags;
    string FileName;
    string FileName;
    
    
    public:
    public:
    enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny};
    enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny};
    
    
-   bool Read(void *To,unsigned long Size);
+   bool Read(void *To,unsigned long Size,bool AllowEof = false);
    bool Write(const void *From,unsigned long Size);
    bool Write(const void *From,unsigned long Size);
    bool Seek(unsigned long To);
    bool Seek(unsigned long To);
    bool Skip(unsigned long To);
    bool Skip(unsigned long To);
@@ -56,6 +57,7 @@ class FileFd
    inline bool Failed() {return (Flags & Fail) == Fail;};
    inline bool Failed() {return (Flags & Fail) == Fail;};
    inline void EraseOnFailure() {Flags |= DelOnFail;};
    inline void EraseOnFailure() {Flags |= DelOnFail;};
    inline void OpFail() {Flags |= Fail;};
    inline void OpFail() {Flags |= Fail;};
+   inline bool Eof() {return (Flags & HitEof) == HitEof;};
    inline string &Name() {return FileName;};
    inline string &Name() {return FileName;};
    
    
    FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1), 
    FileFd(string FileName,OpenMode Mode,unsigned long Perms = 0666) : iFd(-1), 
@@ -76,6 +78,7 @@ void SetCloseExec(int Fd,bool Close);
 void SetNonBlock(int Fd,bool Block);
 void SetNonBlock(int Fd,bool Block);
 bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 bool WaitFd(int Fd,bool write = false,unsigned long timeout = 0);
 int ExecFork();
 int ExecFork();
+bool ExecWait(int Pid,const char *Name,bool Reap = false);
 
 
 // File string manipulators
 // File string manipulators
 string flNotDir(string File);
 string flNotDir(string File);

+ 28 - 1
apt-pkg/contrib/strutl.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: strutl.cc,v 1.26 1999/06/27 04:55:54 jgg Exp $
+// $Id: strutl.cc,v 1.27 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    String Util - Some usefull string functions.
    String Util - Some usefull string functions.
@@ -666,6 +666,33 @@ bool StrToTime(string Val,time_t &Result)
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// StrToNum - Convert a fixed length string to a number			/*{{{*/
+// ---------------------------------------------------------------------
+/* This is used in decoding the crazy fixed length string headers in 
+   tar and ar files. */
+bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base)
+{
+   char S[30];
+   if (Len >= sizeof(S))
+      return false;
+   memcpy(S,Str,Len);
+   S[Len] = 0;
+   
+   // All spaces is a zero
+   Res = 0;
+   unsigned I;
+   for (I = 0; S[I] == ' '; I++);
+   if (S[I] == 0)
+      return true;
+   
+   char *End;
+   Res = strtoul(S,&End,Base);
+   if (End == S)
+      return false;
+   
+   return true;
+}
+									/*}}}*/
 
 
 // URI::CopyFrom - Copy from an object					/*{{{*/
 // URI::CopyFrom - Copy from an object					/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------

+ 2 - 1
apt-pkg/contrib/strutl.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: strutl.h,v 1.13 1999/05/27 05:54:41 jgg Exp $
+// $Id: strutl.h,v 1.14 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    String Util - These are some usefull string functions
    String Util - These are some usefull string functions
@@ -41,6 +41,7 @@ bool StrToTime(string Val,time_t &Result);
 string LookupTag(string Message,const char *Tag,const char *Default = 0);
 string LookupTag(string Message,const char *Tag,const char *Default = 0);
 int StringToBool(string Text,int Default = -1);
 int StringToBool(string Text,int Default = -1);
 bool ReadMessages(int Fd, vector<string> &List);
 bool ReadMessages(int Fd, vector<string> &List);
+bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0);
 
 
 int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
 int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
 inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
 inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};

+ 7 - 6
apt-pkg/deb/deblistparser.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: deblistparser.cc,v 1.20 1999/06/04 05:54:20 jgg Exp $
+// $Id: deblistparser.cc,v 1.21 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -24,6 +24,7 @@
 /* */
 /* */
 debListParser::debListParser(FileFd &File) : Tags(File)
 debListParser::debListParser(FileFd &File) : Tags(File)
 {
 {
+   Arch = _config->Find("APT::architecture");
 }
 }
 									/*}}}*/
 									/*}}}*/
 // ListParser::UniqFindTagWrite - Find the tag and write a unq string	/*{{{*/
 // ListParser::UniqFindTagWrite - Find the tag and write a unq string	/*{{{*/
@@ -157,7 +158,7 @@ unsigned short debListParser::VersionHash()
       char *I = S;
       char *I = S;
       for (; Start != End; Start++)
       for (; Start != End; Start++)
 	 if (isspace(*Start) == 0)
 	 if (isspace(*Start) == 0)
-	    *I++ = *Start;
+	    *I++ = tolower(*Start);
       
       
       Result = AddCRC16(Result,S,I - S);
       Result = AddCRC16(Result,S,I - S);
    }
    }
@@ -466,11 +467,11 @@ bool debListParser::GrabWord(string Word,WordList *List,int Count,
 bool debListParser::Step()
 bool debListParser::Step()
 {
 {
    iOffset = Tags.Offset();
    iOffset = Tags.Offset();
-   string Arch = _config->Find("APT::architecture");
    while (Tags.Step(Section) == true)
    while (Tags.Step(Section) == true)
-   {
-      /* See if this is the correct Architecture, if it isnt then we
-         drop the whole section */
+   {      
+      /* See if this is the correct Architecture, if it isn't then we
+         drop the whole section. A missing arch tag only happens (in theory)
+         inside the Status file, so that is a positive return */
       const char *Start;
       const char *Start;
       const char *Stop;
       const char *Stop;
       if (Section.Find("Architecture",Start,Stop) == false)
       if (Section.Find("Architecture",Start,Stop) == false)

+ 2 - 1
apt-pkg/deb/deblistparser.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: deblistparser.h,v 1.7 1999/05/23 22:55:55 jgg Exp $
+// $Id: deblistparser.h,v 1.8 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Debian Package List Parser - This implements the abstract parser 
    Debian Package List Parser - This implements the abstract parser 
@@ -20,6 +20,7 @@ class debListParser : public pkgCacheGenerator::ListParser
    pkgTagFile Tags;
    pkgTagFile Tags;
    pkgTagSection Section;
    pkgTagSection Section;
    unsigned long iOffset;
    unsigned long iOffset;
+   string Arch;
    
    
    // Parser Helper
    // Parser Helper
    struct WordList
    struct WordList

+ 51 - 37
apt-pkg/deb/dpkginit.cc

@@ -1,10 +1,14 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: dpkginit.cc,v 1.2 1999/04/18 06:36:36 jgg Exp $
+// $Id: dpkginit.cc,v 1.3 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    DPKG init - Initialize the dpkg stuff
    DPKG init - Initialize the dpkg stuff
 
 
+   This class provides the locking mechanism used by dpkg for its 
+   database area. It does the proper consistency checks and acquires the
+   correct kind of lock.
+   
    ##################################################################### */
    ##################################################################### */
 									/*}}}*/
 									/*}}}*/
 // Includes								/*{{{*/
 // Includes								/*{{{*/
@@ -24,10 +28,10 @@
 // DpkgLock::pkgDpkgLock - Constructor					/*{{{*/
 // DpkgLock::pkgDpkgLock - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-pkgDpkgLock::pkgDpkgLock()
+pkgDpkgLock::pkgDpkgLock(bool WithUpdates)
 {
 {
    LockFD = -1;
    LockFD = -1;
-   GetLock();
+   GetLock(WithUpdates);
 }
 }
 									/*}}}*/
 									/*}}}*/
 // DpkgLock::~pkgDpkgLock - Destructor					/*{{{*/
 // DpkgLock::~pkgDpkgLock - Destructor					/*{{{*/
@@ -42,7 +46,7 @@ pkgDpkgLock::~pkgDpkgLock()
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This mirrors the operations dpkg does when it starts up. Note the
 /* This mirrors the operations dpkg does when it starts up. Note the
    checking of the updates directory. */
    checking of the updates directory. */
-bool pkgDpkgLock::GetLock()
+bool pkgDpkgLock::GetLock(bool WithUpdates)
 {
 {
    // Disable file locking
    // Disable file locking
    if (_config->FindB("Debug::NoLocking",false) == true)
    if (_config->FindB("Debug::NoLocking",false) == true)
@@ -56,41 +60,15 @@ bool pkgDpkgLock::GetLock()
    if (LockFD == -1)
    if (LockFD == -1)
       return _error->Error("Unable to lock the administration directory, "
       return _error->Error("Unable to lock the administration directory, "
 			   "are you root?");
 			   "are you root?");
-   
-   // Check for updates.. (dirty)
-   string File = AdminDir + "updates/";
-   DIR *DirP = opendir(File.c_str());
-   if (DirP != 0)
+
+   // See if we need to abort with a dirty journal
+   if (WithUpdates == true && CheckUpdates() == false)
    {
    {
-      /* We ignore any files that are not all digits, this skips .,.. and 
-         some tmp files dpkg will leave behind.. */
-      bool Damaged = false;
-      for (struct dirent *Ent = readdir(DirP); Ent != 0; Ent = readdir(DirP))
-      {
-	 Damaged = true;
-	 for (unsigned int I = 0; Ent->d_name[I] != 0; I++)
-	 {
-	    // Check if its not a digit..
-	    if (isdigit(Ent->d_name[I]) == 0)
-	    {
-	       Damaged = false;
-	       break;
-	    }
-	 }
-	 if (Damaged == true)
-	    break;
-      }
-      closedir(DirP);
-       	 
-      // Woops, we have to run dpkg to rewrite the status file
-      if (Damaged == true)
-      {
-	 Close();
-	 return _error->Error("dpkg was interrupted, you must manually "
-			      "run 'dpkg --configure -a' to correct the problem. ");
-      }
+      Close();
+      return _error->Error("dpkg was interrupted, you must manually "
+			   "run 'dpkg --configure -a' to correct the problem. ");
    }
    }
-   
+      
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -103,3 +81,39 @@ void pkgDpkgLock::Close()
    LockFD = -1;
    LockFD = -1;
 }
 }
 									/*}}}*/
 									/*}}}*/
+// DpkgLock::CheckUpdates - Check if the updates dir is dirty		/*{{{*/
+// ---------------------------------------------------------------------
+/* This does a check of the updates directory to see if it has any entries
+   in it. */
+bool pkgDpkgLock::CheckUpdates()
+{
+   // Check for updates.. (dirty)
+   string File = flNotFile(_config->Find("Dir::State::status")) + "updates/";
+   DIR *DirP = opendir(File.c_str());
+   if (DirP == 0)
+      return true;
+   
+   /* We ignore any files that are not all digits, this skips .,.. and 
+      some tmp files dpkg will leave behind.. */
+   bool Damaged = false;
+   for (struct dirent *Ent = readdir(DirP); Ent != 0; Ent = readdir(DirP))
+   {
+      Damaged = true;
+      for (unsigned int I = 0; Ent->d_name[I] != 0; I++)
+      {
+	 // Check if its not a digit..
+	 if (isdigit(Ent->d_name[I]) == 0)
+	 {
+	    Damaged = false;
+	    break;
+	 }
+      }
+      if (Damaged == true)
+	 break;
+   }
+   closedir(DirP);
+
+   return Damaged;
+}
+									/*}}}*/
+   

+ 5 - 4
apt-pkg/deb/dpkginit.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: dpkginit.h,v 1.1 1998/11/23 07:03:11 jgg Exp $
+// $Id: dpkginit.h,v 1.2 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    DPKG init - Initialize the dpkg stuff
    DPKG init - Initialize the dpkg stuff
@@ -23,10 +23,11 @@ class pkgDpkgLock
       
       
    public:
    public:
    
    
-   bool GetLock();
+   bool CheckUpdates();
+   bool GetLock(bool WithUpdates);
    void Close();
    void Close();
-   
-   pkgDpkgLock();
+
+   pkgDpkgLock(bool WithUpdates = true);
    ~pkgDpkgLock();
    ~pkgDpkgLock();
 };
 };
 
 

+ 2 - 2
apt-pkg/deb/dpkgpm.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: dpkgpm.cc,v 1.11 1999/07/09 04:11:34 jgg Exp $
+// $Id: dpkgpm.cc,v 1.12 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
 
 
    DPKG Package Manager - Provide an interface to dpkg
    DPKG Package Manager - Provide an interface to dpkg
@@ -121,7 +121,7 @@ bool pkgDPkgPM::RunScripts(const char *Cnf)
    // Restore sig int/quit
    // Restore sig int/quit
    signal(SIGQUIT,SIG_DFL);
    signal(SIGQUIT,SIG_DFL);
    signal(SIGINT,SIG_DFL);   
    signal(SIGINT,SIG_DFL);   
-       
+
    // Check for an error code.
    // Check for an error code.
    if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
    if (WIFEXITED(Status) == 0 || WEXITSTATUS(Status) != 0)
    {
    {

+ 2 - 2
apt-pkg/pkgcache.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcache.cc,v 1.26 1999/06/04 05:54:20 jgg Exp $
+// $Id: pkgcache.cc,v 1.27 1999/07/26 17:46:07 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache - Accessor code for the cache
    Package Cache - Accessor code for the cache
@@ -44,7 +44,7 @@ pkgCache::Header::Header()
    /* Whenever the structures change the major version should be bumped,
    /* Whenever the structures change the major version should be bumped,
       whenever the generator changes the minor version should be bumped. */
       whenever the generator changes the minor version should be bumped. */
    MajorVersion = 3;
    MajorVersion = 3;
-   MinorVersion = 2;
+   MinorVersion = 3;
    Dirty = true;
    Dirty = true;
    
    
    HeaderSz = sizeof(pkgCache::Header);
    HeaderSz = sizeof(pkgCache::Header);

+ 34 - 13
apt-pkg/pkgcachegen.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcachegen.cc,v 1.40 1999/07/15 03:15:48 jgg Exp $
+// $Id: pkgcachegen.cc,v 1.41 1999/07/26 17:46:07 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -33,8 +33,10 @@
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* We set the diry flag and make sure that is written to the disk */
 /* We set the diry flag and make sure that is written to the disk */
 pkgCacheGenerator::pkgCacheGenerator(DynamicMMap &Map,OpProgress &Prog) :
 pkgCacheGenerator::pkgCacheGenerator(DynamicMMap &Map,OpProgress &Prog) :
-                    Map(Map), Cache(Map), Progress(Prog)
+                    Map(Map), Cache(Map), Progress(&Prog)
 {
 {
+   CurrentFile = 0;
+   
    if (_error->PendingError() == true)
    if (_error->PendingError() == true)
       return;
       return;
    
    
@@ -68,7 +70,8 @@ pkgCacheGenerator::~pkgCacheGenerator()
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This provides the generation of the entries in the cache. Each loop
 /* This provides the generation of the entries in the cache. Each loop
    goes through a single package record from the underlying parse engine. */
    goes through a single package record from the underlying parse engine. */
-bool pkgCacheGenerator::MergeList(ListParser &List)
+bool pkgCacheGenerator::MergeList(ListParser &List,
+				  pkgCache::VerIterator *OutVer)
 {
 {
    List.Owner = this;
    List.Owner = this;
 
 
@@ -84,8 +87,8 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
       if (NewPackage(Pkg,PackageName) == false)
       if (NewPackage(Pkg,PackageName) == false)
 	 return _error->Error("Error occured while processing %s (NewPackage)",PackageName.c_str());
 	 return _error->Error("Error occured while processing %s (NewPackage)",PackageName.c_str());
       Counter++;
       Counter++;
-      if (Counter % 100 == 0)
-	 Progress.Progress(List.Offset());
+      if (Counter % 100 == 0 && Progress != 0)
+	 Progress->Progress(List.Offset());
 
 
       /* Get a pointer to the version structure. We know the list is sorted
       /* Get a pointer to the version structure. We know the list is sorted
          so we use that fact in the search. Insertion of new versions is
          so we use that fact in the search. Insertion of new versions is
@@ -120,6 +123,13 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
 	 if (NewFileVer(Ver,List) == false)
 	 if (NewFileVer(Ver,List) == false)
 	    return _error->Error("Error occured while processing %s (NewFileVer1)",PackageName.c_str());
 	    return _error->Error("Error occured while processing %s (NewFileVer1)",PackageName.c_str());
 	 
 	 
+	 // Read only a single record and return
+	 if (OutVer != 0)
+	 {
+	    *OutVer = Ver;
+	    return true;
+	 }
+	 
 	 continue;
 	 continue;
       }      
       }      
 
 
@@ -147,6 +157,13 @@ bool pkgCacheGenerator::MergeList(ListParser &List)
       
       
       if (NewFileVer(Ver,List) == false)
       if (NewFileVer(Ver,List) == false)
 	 return _error->Error("Error occured while processing %s (NewVersion2)",PackageName.c_str());
 	 return _error->Error("Error occured while processing %s (NewVersion2)",PackageName.c_str());
+
+      // Read only a single record and return
+      if (OutVer != 0)
+      {
+	 *OutVer = Ver;
+	 return true;
+      }      
    }
    }
 
 
    return true;
    return true;
@@ -188,6 +205,9 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,string Name)
 bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
 bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
 				   ListParser &List)
 				   ListParser &List)
 {
 {
+   if (CurrentFile == 0)
+      return true;
+   
    // Get a structure
    // Get a structure
    unsigned long VerFile = Map.Allocate(sizeof(pkgCache::VerFile));
    unsigned long VerFile = Map.Allocate(sizeof(pkgCache::VerFile));
    if (VerFile == 0)
    if (VerFile == 0)
@@ -366,7 +386,8 @@ bool pkgCacheGenerator::SelectFile(string File,unsigned long Flags)
    if (CurrentFile->FileName == 0)
    if (CurrentFile->FileName == 0)
       return false;
       return false;
    
    
-   Progress.SubProgress(Buf.st_size);
+   if (Progress != 0)
+      Progress->SubProgress(Buf.st_size);
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -572,10 +593,10 @@ bool pkgPkgCacheCheck(string CacheFile)
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
-// AddSourcesSize - Add the size of the status files			/*{{{*/
+// AddStatusSize - Add the size of the status files			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This adds the size of all the status files to the size counter */
 /* This adds the size of all the status files to the size counter */
-static bool pkgAddSourcesSize(unsigned long &TotalSize)
+bool pkgAddStatusSize(unsigned long &TotalSize)
 {
 {
    // Grab the file names
    // Grab the file names
    string xstatus = _config->FindFile("Dir::State::xstatus");
    string xstatus = _config->FindFile("Dir::State::xstatus");
@@ -598,8 +619,8 @@ static bool pkgAddSourcesSize(unsigned long &TotalSize)
 // MergeStatus - Add the status files to the cache			/*{{{*/
 // MergeStatus - Add the status files to the cache			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* This adds the status files to the map */
 /* This adds the status files to the map */
-static bool pkgMergeStatus(OpProgress &Progress,pkgCacheGenerator &Gen,
-			   unsigned long &CurrentSize,unsigned long TotalSize)
+bool pkgMergeStatus(OpProgress &Progress,pkgCacheGenerator &Gen,
+		    unsigned long &CurrentSize,unsigned long TotalSize)
 {
 {
    // Grab the file names   
    // Grab the file names   
    string Status[3];
    string Status[3];
@@ -653,7 +674,7 @@ bool pkgGenerateSrcCache(pkgSourceList &List,OpProgress &Progress,
       TotalSize += Buf.st_size;
       TotalSize += Buf.st_size;
    }
    }
    
    
-   if (pkgAddSourcesSize(TotalSize) == false)
+   if (pkgAddStatusSize(TotalSize) == false)
       return false;
       return false;
    
    
    // Generate the pkg source cache
    // Generate the pkg source cache
@@ -759,7 +780,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress)
    
    
    // Compute the progress
    // Compute the progress
    unsigned long TotalSize = 0;
    unsigned long TotalSize = 0;
-   if (pkgAddSourcesSize(TotalSize) == false)
+   if (pkgAddStatusSize(TotalSize) == false)
       return false;
       return false;
 
 
    unsigned long CurrentSize = 0;
    unsigned long CurrentSize = 0;
@@ -873,7 +894,7 @@ MMap *pkgMakeStatusCacheMem(pkgSourceList &List,OpProgress &Progress)
    
    
    // Compute the progress
    // Compute the progress
    unsigned long TotalSize = 0;
    unsigned long TotalSize = 0;
-   if (pkgAddSourcesSize(TotalSize) == false)
+   if (pkgAddStatusSize(TotalSize) == false)
    {
    {
       delete Map;
       delete Map;
       return 0;
       return 0;

+ 8 - 3
apt-pkg/pkgcachegen.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
 // Description								/*{{{*/
-// $Id: pkgcachegen.h,v 1.16 1999/07/15 03:15:48 jgg Exp $
+// $Id: pkgcachegen.h,v 1.17 1999/07/26 17:46:08 jgg Exp $
 /* ######################################################################
 /* ######################################################################
    
    
    Package Cache Generator - Generator for the cache structure.
    Package Cache Generator - Generator for the cache structure.
@@ -45,7 +45,7 @@ class pkgCacheGenerator
    
    
    DynamicMMap &Map;
    DynamicMMap &Map;
    pkgCache Cache;
    pkgCache Cache;
-   OpProgress &Progress;
+   OpProgress *Progress;
    
    
    string PkgFileName;
    string PkgFileName;
    pkgCache::PackageFile *CurrentFile;
    pkgCache::PackageFile *CurrentFile;
@@ -59,8 +59,9 @@ class pkgCacheGenerator
 
 
    public:   
    public:   
 
 
+   void DropProgress() {Progress = 0;};
    bool SelectFile(string File,unsigned long Flags = 0);
    bool SelectFile(string File,unsigned long Flags = 0);
-   bool MergeList(ListParser &List);
+   bool MergeList(ListParser &List,pkgCache::VerIterator *Ver = 0);
    inline pkgCache &GetCache() {return Cache;};
    inline pkgCache &GetCache() {return Cache;};
    inline pkgCache::PkgFileIterator GetCurFile() 
    inline pkgCache::PkgFileIterator GetCurFile() 
          {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
          {return pkgCache::PkgFileIterator(Cache,CurrentFile);};
@@ -112,4 +113,8 @@ class pkgCacheGenerator::ListParser
    virtual ~ListParser() {};
    virtual ~ListParser() {};
 };
 };
 
 
+bool pkgMergeStatus(OpProgress &Progress,pkgCacheGenerator &Gen,
+		    unsigned long &CurrentSize,unsigned long TotalSize);
+bool pkgAddStatusSize(unsigned long &TotalSize);
+
 #endif
 #endif