]> git.saurik.com Git - apt.git/commitdiff
Needs Unpack fixes
authorArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:51:37 +0000 (16:51 +0000)
committerArch Librarian <arch@canonical.com>
Mon, 20 Sep 2004 16:51:37 +0000 (16:51 +0000)
Author: jgg
Date: 1998-11-23 07:02:58 GMT
Needs Unpack fixes

13 files changed:
apt-pkg/algorithms.cc
apt-pkg/contrib/fileutl.cc
apt-pkg/contrib/fileutl.h
apt-pkg/contrib/mmap.cc
apt-pkg/deb/dpkginit.cc [new file with mode: 0644]
apt-pkg/deb/dpkginit.h [new file with mode: 0644]
apt-pkg/deb/dpkgpm.cc
apt-pkg/deb/dpkgpm.h
apt-pkg/depcache.cc
apt-pkg/makefile
apt-pkg/packagemanager.cc
apt-pkg/pkgcache.cc
cmdline/apt-get.cc

index 21009581004dc17da55f13fc8b7d684b2b5e72b5..6328a20ebd12475ee388563a87d524c2e078dd64 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: algorithms.cc,v 1.11 1998/11/14 07:20:06 jgg Exp $
+// $Id: algorithms.cc,v 1.12 1998/11/23 07:02:58 jgg Exp $
 /* ######################################################################
 
    Algorithms - A set of misc algorithms
@@ -165,6 +165,14 @@ bool pkgApplyStatus(pkgDepCache &Cache)
 {
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {
+      // Only choice for a ReInstReq package is to reinstall
+      if (I->InstState == pkgCache::State::ReInstReq ||
+         I->InstState == pkgCache::State::HoldReInstReq)
+      {
+        Cache.MarkKeep(I);
+        continue;
+      }
+      
       switch (I->CurrentState)
       {
         // This means installation failed somehow
index 77e846117bc8778c87117bae05edbc0a455f6c13..3ca36377a2095b2008fc27f70d251652084b850e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.cc,v 1.13 1998/10/26 07:11:49 jgg Exp $
+// $Id: fileutl.cc,v 1.14 1998/11/23 07:03:06 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -119,6 +119,18 @@ string flNotDir(string File)
    return string(File,Res,Res - File.length());
 }
                                                                        /*}}}*/
+// flNotFile - Strip the file from the directory name                  /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string flNotFile(string File)
+{
+   string::size_type Res = File.rfind('/');
+   if (Res == string::npos)
+      return File;
+   Res++;
+   return string(File,0,Res);
+}
+                                                                       /*}}}*/
 // SetCloseExec - Set the close on exec flag                           /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -184,12 +196,7 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
 
       case WriteAny:
       iFd = open(FileName.c_str(),O_RDWR | O_CREAT,Perms);
-      break;
-      
-      // Dont use this in public directories
-      case LockEmpty:
-      iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms);
-      break;
+      break;      
    }  
 
    if (iFd < 0)
index 01dc46b1355669c2ea2c1a2a70207cdf07ffc9ff..31af3d28b234cd0aaa7548bdde2926c69f22303a 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: fileutl.h,v 1.8 1998/10/26 07:11:50 jgg Exp $
+// $Id: fileutl.h,v 1.9 1998/11/23 07:03:07 jgg Exp $
 /* ######################################################################
    
    File Utilities
@@ -38,7 +38,7 @@ class FileFd
    string FileName;
    
    public:
-   enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,LockEmpty};
+   enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny};
    
    bool Read(void *To,unsigned long Size);
    bool Write(void *From,unsigned long Size);
@@ -69,5 +69,6 @@ bool WaitFd(int Fd);
 
 // File string manipulators
 string flNotDir(string File);
+string flNotFile(string File);
 
 #endif
index f6def2154750ba33b930145c2abd4de6ba72669b..0ac202aef7fc2bce497b4157460b36ceef15c308 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: mmap.cc,v 1.9 1998/11/12 03:14:39 jgg Exp $
+// $Id: mmap.cc,v 1.10 1998/11/23 07:03:08 jgg Exp $
 /* ######################################################################
    
    MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -130,6 +130,9 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
 DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace) : 
              MMap(F,Flags | NoImmMap), WorkSpace(WorkSpace)
 {
+   if (_error->PendingError() == true)
+      return;
+   
    unsigned long EndOfFile = Fd.Size();
    Fd.Seek(WorkSpace);
    char C = 0;
diff --git a/apt-pkg/deb/dpkginit.cc b/apt-pkg/deb/dpkginit.cc
new file mode 100644 (file)
index 0000000..095156d
--- /dev/null
@@ -0,0 +1,105 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+// $Id: dpkginit.cc,v 1.1 1998/11/23 07:03:10 jgg Exp $
+/* ######################################################################
+
+   DPKG init - Initialize the dpkg stuff
+
+   ##################################################################### */
+                                                                       /*}}}*/
+// Includes                                                            /*{{{*/
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/dpkginit.h"
+#endif
+#include <apt-pkg/dpkginit.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirent.h>
+                                                                       /*}}}*/
+
+// DpkgLock::pkgDpkgLock - Constructor                                 /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgDpkgLock::pkgDpkgLock()
+{
+   LockFD = -1;
+   GetLock();
+}
+                                                                       /*}}}*/
+// DpkgLock::~pkgDpkgLock - Destructor                                 /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgDpkgLock::~pkgDpkgLock()
+{
+   Close();
+}
+                                                                       /*}}}*/
+// DpkgLock::GetLock - Get the lock                                    /*{{{*/
+// ---------------------------------------------------------------------
+/* This mirrors the operations dpkg does when it starts up. Note the
+   checking of the updates directory. */
+bool pkgDpkgLock::GetLock()
+{
+   // Disable file locking
+   if (_config->FindB("Debug::NoLocking",false) == true)
+      return true;
+   
+   Close();
+   
+   // Create the lockfile
+   string AdminDir = flNotFile(_config->Find("Dir::State::status"));
+   LockFD = ::GetLock(AdminDir + "lock");
+   if (LockFD == -1)
+      return _error->Errno("Open","Unable to lock the administration directory "
+                          "%s, are you root?",AdminDir.c_str());
+   
+   // Check for updates.. (dirty)
+   string File = AdminDir + "updates/";
+   DIR *DirP = opendir(File.c_str());
+   if (DirP != 0)
+   {
+      /* 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. ");
+      }
+   }
+   
+   return true;
+}
+                                                                       /*}}}*/
+// DpkgLock::Close - Close the lock                                    /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgDpkgLock::Close()
+{
+   close(LockFD);
+   LockFD = -1;
+}
+                                                                       /*}}}*/
diff --git a/apt-pkg/deb/dpkginit.h b/apt-pkg/deb/dpkginit.h
new file mode 100644 (file)
index 0000000..288f50d
--- /dev/null
@@ -0,0 +1,33 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+// $Id: dpkginit.h,v 1.1 1998/11/23 07:03:11 jgg Exp $
+/* ######################################################################
+
+   DPKG init - Initialize the dpkg stuff
+   
+   This basically gets a lock in /var/lib/dpkg and checks the updates
+   directory
+   
+   ##################################################################### */
+                                                                       /*}}}*/
+#ifndef PKGLIB_DPKGINIT_H
+#define PKGLIB_DPKGINIT_H
+
+#ifdef __GNUG__
+#pragma interface "apt-pkg/dpkginit.h"
+#endif
+
+class pkgDpkgLock
+{
+   int LockFD;
+      
+   public:
+   
+   bool GetLock();
+   void Close();
+   
+   pkgDpkgLock();
+   ~pkgDpkgLock();
+};
+
+#endif
index dfdc0c4b527617b7b2c1e1799e38f1c6f7fa7ebb..e437ad7a31c282e2c66f96540dc6bc5d9b4829c0 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: dpkgpm.cc,v 1.2 1998/11/22 03:20:35 jgg Exp $
+// $Id: dpkgpm.cc,v 1.3 1998/11/23 07:03:11 jgg Exp $
 /* ######################################################################
 
    DPKG Package Manager - Provide an interface to dpkg
@@ -163,6 +163,7 @@ bool pkgDPkgPM::Go()
       // This is the child
       if (Child == 0)
       {
+        signal(SIGPIPE,SIG_DFL);
         signal(SIGQUIT,SIG_DFL);
         signal(SIGINT,SIG_DFL);
         signal(SIGWINCH,SIG_DFL);
index b5f08ea32fe2d9e3ac5e9ce922df34b8d06a31d5..dcb6e9db0b6e9a546edd0917f04c14062af23c8d 100644 (file)
@@ -1,13 +1,12 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: dpkgpm.h,v 1.1 1998/11/13 04:23:39 jgg Exp $
+// $Id: dpkgpm.h,v 1.2 1998/11/23 07:03:12 jgg Exp $
 /* ######################################################################
 
    DPKG Package Manager - Provide an interface to dpkg
    
    ##################################################################### */
                                                                        /*}}}*/
-// Header section: pkglib
 #ifndef PKGLIB_DPKGPM_H
 #define PKGLIB_DPKGPM_H
 
index 90c07658be4ae10c6b694e888d3c46df9d206bdd..b3a70d2390599e145db4fbe865705e4afa23e9a1 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: depcache.cc,v 1.6 1998/11/23 01:45:58 jgg Exp $
+// $Id: depcache.cc,v 1.7 1998/11/23 07:02:59 jgg Exp $
 /* ######################################################################
 
    Dependency Cache - Caches Dependency information.
@@ -213,6 +213,7 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,long Mult)
    {
       iUsrSize += Mult*P.InstVerIter(*this)->InstalledSize;
       iDownloadSize += Mult*P.InstVerIter(*this)->Size;
+      return;
    }
    
    // Upgrading
@@ -222,11 +223,22 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,long Mult)
       iUsrSize += Mult*((signed)P.InstVerIter(*this)->InstalledSize - 
                        (signed)Pkg.CurrentVer()->InstalledSize);
       iDownloadSize += Mult*P.InstVerIter(*this)->Size;
+      return;
+   }
+   
+   // Reinstall
+   if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack)
+   {
+      iDownloadSize += Mult*P.InstVerIter(*this)->Size;
+      return;
    }
    
    // Removing
    if (Pkg->CurrentVer != 0 && P.InstallVer == 0)
+   {
       iUsrSize -= Mult*Pkg.CurrentVer()->InstalledSize;
+      return;
+   }   
 }
                                                                        /*}}}*/
 // DepCache::AddStates - Add the package to the state counter          /*{{{*/
index f981a8895c217493744829bec2759d5781e765c9..d78fb7cdc7678a7d0dca0dc7af4dfdb0c5852c92 100644 (file)
@@ -27,7 +27,7 @@ SOURCE+= pkgcache.cc version.cc fileutl.cc pkgcachegen.cc depcache.cc \
         acquire-worker.cc acquire-method.cc init.cc templates.cc
 
 # Source code for the debian specific components        
-SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.cc
+SOURCE+= deb/deblistparser.cc deb/debrecords.cc deb/dpkgpm.cc deb/dpkginit.cc
 
 # Public apt-pkg header files
 HEADERS = algorithms.h depcache.h mmap.h pkgcachegen.h cacheiterators.h \
@@ -35,7 +35,7 @@ HEADERS = algorithms.h depcache.h mmap.h pkgcachegen.h cacheiterators.h \
           packagemanager.h tagfile.h deblistparser.h init.h pkgcache.h \
           version.h progress.h pkgrecords.h debrecords.h cmndline.h \
          acquire.h acquire-worker.h acquire-item.h acquire-method.h md5.h \
-         dpkgpm.h
+         dpkgpm.h dpkginit.h
 
 HEADERS := $(addprefix apt-pkg/,$(HEADERS))
 
index 7dd6b8a2785e47640e1e86abfd4a21c2954513d0..04b77eb0941250f36c0d904ed8f5217e02144847 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: packagemanager.cc,v 1.7 1998/11/22 23:37:05 jgg Exp $
+// $Id: packagemanager.cc,v 1.8 1998/11/23 07:03:01 jgg Exp $
 /* ######################################################################
 
    Package Manager - Abstacts the package manager
@@ -64,6 +64,10 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
       // Skip packages to erase
       if (Cache[Pkg].Delete() == true)
         continue;
+
+      // Skip Packages that need configure only.
+      if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure)
+        continue;
       
       new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
                        FileNames[Pkg->ID]);
@@ -106,15 +110,19 @@ bool pkgPackageManager::CreateOrderList()
    // Generate the list of affected packages and sort it
    for (PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
    {
-      // Consider all depends
+      // Mark the package for immediate configuration
       if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
       {
         List->Flag(I,pkgOrderList::Immediate);
+        
+        // Look for other packages to make immediate configurea
         if (Cache[I].InstallVer != 0)
            for (DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); 
                 D.end() == false; D++)
               if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
                  List->Flag(D.TargetPkg(),pkgOrderList::Immediate);
+        
+        // And again with the current version.
         if (I->CurrentVer != 0)
            for (DepIterator D = I.CurrentVer().DependsList(); 
                 D.end() == false; D++)
index 2b52a9977eb19a85ed3b7f957f59164f893053bb..2fbdc717fb050b22e8468ca125e20ef0ddbfd7fa 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: pkgcache.cc,v 1.16 1998/11/14 07:20:09 jgg Exp $
+// $Id: pkgcache.cc,v 1.17 1998/11/23 07:03:05 jgg Exp $
 /* ######################################################################
    
    Package Cache - Accessor code for the cache
@@ -203,7 +203,7 @@ void pkgCache::PkgIterator::operator ++(int)
 // ---------------------------------------------------------------------
 /* By this we mean if it is either cleanly installed or cleanly removed. */
 pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const
-{
+{  
    if (Pkg->InstState == pkgCache::State::ReInstReq ||
        Pkg->InstState == pkgCache::State::HoldReInstReq)
       return NeedsUnpack;
index 24a3f8e7f88641b240c9dabf70f8fd6c4e58e91f..c90c0ed549cc03210e0fd06bfca62f301e8a29f7 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: apt-get.cc,v 1.17 1998/11/23 01:45:59 jgg Exp $
+// $Id: apt-get.cc,v 1.18 1998/11/23 07:03:13 jgg Exp $
 /* ######################################################################
    
    apt-get - Cover for dpkg
@@ -34,6 +34,7 @@
 #include <apt-pkg/algorithms.h>
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/dpkgpm.h>
+#include <apt-pkg/dpkginit.h>
 #include <strutl.h>
 
 #include <config.h>
@@ -359,6 +360,7 @@ class CacheFile
    FileFd *File;
    MMap *Map;
    pkgDepCache *Cache;
+   pkgDpkgLock Lock;
    
    inline operator pkgDepCache &() {return *Cache;};
    inline pkgDepCache *operator ->() {return Cache;};
@@ -380,6 +382,9 @@ class CacheFile
    and verifies that the system is OK. */
 bool CacheFile::Open()
 {
+   if (_error->PendingError() == true)
+      return false;
+   
    // Create a progress class
    OpTextProgress Progress(*_config);
       
@@ -454,7 +459,7 @@ bool CacheFile::Open()
 // ---------------------------------------------------------------------
 /* This displays the informative messages describing what is going to 
    happen and then calls the download routines */
-bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
+bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true)
 {
    // Show all the various warning indicators
    ShowDel(c1out,Cache);
@@ -468,14 +473,14 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
    Stats(c1out,Cache);
    
    // Sanity check
-   if (Cache.BrokenCount() != 0)
+   if (Cache->BrokenCount() != 0)
    {
       ShowBroken(c1out,Cache);
       return _error->Error("Internal Error, InstallPackages was called with broken packages!");
    }
 
-   if (Cache.DelCount() == 0 && Cache.InstCount() == 0 && 
-       Cache.BadCount() == 0)
+   if (Cache->DelCount() == 0 && Cache->InstCount() == 0 && 
+       Cache->BadCount() == 0)
       return true;   
 
    // Run the simulator ..
@@ -487,6 +492,14 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
    
    // Create the text record parser
    pkgRecords Recs(Cache);
+
+   // Lock the archive directory
+   if (_config->FindB("Debug::NoLocking",false) == false)
+   {
+      FileFd Lock(GetLock(_config->FindDir("Dir::Cache::Archives") + "lock"));
+      if (_error->PendingError() == true)
+        return _error->Error("Unable to lock the download directory");
+   }
    
    // Create the download object
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));   
@@ -505,9 +518,12 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
    // Display statistics
    unsigned long FetchBytes = Fetcher.FetchNeeded();
    unsigned long DebBytes = Fetcher.TotalNeeded();
-   if (DebBytes != Cache.DebSize())
+   if (DebBytes != Cache->DebSize())
+   {
+      c0out << DebBytes << ',' << Cache->DebSize() << endl;
       c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl;
-   
+   }
+      
    // Number of bytes
    c1out << "Need to get ";
    if (DebBytes != FetchBytes)
@@ -518,10 +534,10 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
    c1out << " of archives. After unpacking ";
    
    // Size delta
-   if (Cache.UsrSize() >= 0)
-      c1out << SizeToStr(Cache.UsrSize()) << " will be used." << endl;
+   if (Cache->UsrSize() >= 0)
+      c1out << SizeToStr(Cache->UsrSize()) << " will be used." << endl;
    else
-      c1out << SizeToStr(-1*Cache.UsrSize()) << " will be freed." << endl;
+      c1out << SizeToStr(-1*Cache->UsrSize()) << " will be freed." << endl;
 
    if (_error->PendingError() == true)
       return false;
@@ -557,12 +573,13 @@ bool InstallPackages(pkgDepCache &Cache,bool ShwKept,bool Ask = true)
       return _error->Error("Unable to fetch some archives, maybe try with --fix-missing?");
 
    // Try to deal with missing package files
-/*   if (PM.FixMissing() == false)
+   if (PM.FixMissing() == false)
    {
       cerr << "Unable to correct missing packages." << endl;
       return _error->Error("Aborting Install.");
-   }*/
+   }
    
+   Cache.Lock.Close();
    return PM.DoInstall();
 }
                                                                        /*}}}*/
@@ -577,6 +594,14 @@ bool DoUpdate(CommandLine &)
    if (List.ReadMainList() == false)
       return false;
 
+   // Lock the list directory
+   if (_config->FindB("Debug::NoLocking",false) == false)
+   {
+      FileFd Lock(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
+      if (_error->PendingError() == true)
+        return _error->Error("Unable to lock the list directory");
+   }
+   
    // Create the download object
    AcqTextStatus Stat(ScreenWidth,_config->FindI("quiet",0));
    pkgAcquire Fetcher(&Stat);