From d38b7b3d803a719b189df80820aeda6a818f4909 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:51:37 +0000 Subject: Needs Unpack fixes Author: jgg Date: 1998-11-23 07:02:58 GMT Needs Unpack fixes --- apt-pkg/algorithms.cc | 10 ++++- apt-pkg/contrib/fileutl.cc | 21 ++++++--- apt-pkg/contrib/fileutl.h | 5 ++- apt-pkg/contrib/mmap.cc | 5 ++- apt-pkg/deb/dpkginit.cc | 105 +++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/deb/dpkginit.h | 33 ++++++++++++++ apt-pkg/deb/dpkgpm.cc | 3 +- apt-pkg/deb/dpkgpm.h | 3 +- apt-pkg/depcache.cc | 14 +++++- apt-pkg/makefile | 4 +- apt-pkg/packagemanager.cc | 12 +++++- apt-pkg/pkgcache.cc | 4 +- cmdline/apt-get.cc | 49 +++++++++++++++------ 13 files changed, 235 insertions(+), 33 deletions(-) create mode 100644 apt-pkg/deb/dpkginit.cc create mode 100644 apt-pkg/deb/dpkginit.h diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 210095810..6328a20eb 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -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 diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 77e846117..3ca36377a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -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) diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 01dc46b13..31af3d28b 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -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 diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index f6def2154..0ac202aef 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -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 index 000000000..095156d0d --- /dev/null +++ b/apt-pkg/deb/dpkginit.cc @@ -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 +#include +#include +#include + +#include +#include +#include + /*}}}*/ + +// 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 index 000000000..288f50d04 --- /dev/null +++ b/apt-pkg/deb/dpkginit.h @@ -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 diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index dfdc0c4b5..e437ad7a3 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -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); diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index b5f08ea32..dcb6e9db0 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -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 diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 90c07658b..b3a70d239 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -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 /*{{{*/ diff --git a/apt-pkg/makefile b/apt-pkg/makefile index f981a8895..d78fb7cdc 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -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)) diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index 7dd6b8a27..04b77eb09 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -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++) diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 2b52a9977..2fbdc717f 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -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; diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 24a3f8e7f..c90c0ed54 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -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 #include #include +#include #include #include @@ -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); -- cgit v1.2.3