diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/algorithms.cc | 33 | ||||
-rw-r--r-- | apt-pkg/algorithms.h | 2 | ||||
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 67 | ||||
-rw-r--r-- | apt-pkg/cacheiterators.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.cc | 10 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 24 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.cc | 2 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 58 | ||||
-rw-r--r-- | apt-pkg/depcache.cc | 39 | ||||
-rw-r--r-- | apt-pkg/packagemanager.cc | 21 |
10 files changed, 183 insertions, 75 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index f7a333606..c337ace87 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -475,7 +475,7 @@ pkgProblemResolver::pkgProblemResolver(pkgDepCache *pCache) : Cache(*pCache) { // Allocate memory unsigned long Size = Cache.Head().PackageCount; - Scores = new signed short[Size]; + Scores = new int[Size]; Flags = new unsigned char[Size]; memset(Flags,0,sizeof(*Flags)*Size); @@ -515,20 +515,20 @@ void pkgProblemResolver::MakeScores() memset(Scores,0,sizeof(*Scores)*Size); // Important Required Standard Optional Extra - signed short PrioMap[] = { + int PrioMap[] = { 0, - (signed short) _config->FindI("pkgProblemResolver::Scores::Important",3), - (signed short) _config->FindI("pkgProblemResolver::Scores::Required",2), - (signed short) _config->FindI("pkgProblemResolver::Scores::Standard",1), - (signed short) _config->FindI("pkgProblemResolver::Scores::Optional",-1), - (signed short) _config->FindI("pkgProblemResolver::Scores::Extra",-2) + _config->FindI("pkgProblemResolver::Scores::Important",3), + _config->FindI("pkgProblemResolver::Scores::Required",2), + _config->FindI("pkgProblemResolver::Scores::Standard",1), + _config->FindI("pkgProblemResolver::Scores::Optional",-1), + _config->FindI("pkgProblemResolver::Scores::Extra",-2) }; - signed short PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100); - signed short PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1); - signed short PrioDepends = _config->FindI("pkgProblemResolver::Scores::Depends",1); - signed short PrioRecommends = _config->FindI("pkgProblemResolver::Scores::Recommends",1); - signed short AddProtected = _config->FindI("pkgProblemResolver::Scores::AddProtected",10000); - signed short AddEssential = _config->FindI("pkgProblemResolver::Scores::AddEssential",5000); + int PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100); + int PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1); + int PrioDepends = _config->FindI("pkgProblemResolver::Scores::Depends",1); + int PrioRecommends = _config->FindI("pkgProblemResolver::Scores::Recommends",1); + int AddProtected = _config->FindI("pkgProblemResolver::Scores::AddProtected",10000); + int AddEssential = _config->FindI("pkgProblemResolver::Scores::AddEssential",5000); if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true) clog << "Settings used to calculate pkgProblemResolver::Scores::" << endl @@ -550,7 +550,7 @@ void pkgProblemResolver::MakeScores() if (Cache[I].InstallVer == 0) continue; - signed short &Score = Scores[I->ID]; + int &Score = Scores[I->ID]; /* This is arbitrary, it should be high enough to elevate an essantial package above most other packages but low enough @@ -588,7 +588,7 @@ void pkgProblemResolver::MakeScores() } // Copy the scores to advoid additive looping - SPtrArray<signed short> OldScores = new signed short[Size]; + SPtrArray<int> OldScores = new int[Size]; memcpy(OldScores,Scores,sizeof(*Scores)*Size); /* Now we cause 1 level of dependency inheritance, that is we add the @@ -1098,8 +1098,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix) LEnd->Dep = End; LEnd++; - if (Start->Type != pkgCache::Dep::Conflicts && - Start->Type != pkgCache::Dep::Obsoletes) + if (Start.IsNegative() == false) break; } } diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index 185d11e96..37eacf1f8 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -96,7 +96,7 @@ class pkgProblemResolver /*{{{*/ enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1), Upgradable = (1 << 2), ReInstateTried = (1 << 3), ToRemove = (1 << 4)}; - signed short *Scores; + int *Scores; unsigned char *Flags; bool Debug; diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 7441b452c..b5ad74831 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -20,6 +20,7 @@ #include <sys/types.h> #include <dirent.h> #include <stdio.h> +#include <fcntl.h> #include <algorithm> #include <string> @@ -328,16 +329,63 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache // FIXME: It is a bit unclean to have debian specific code hereā¦ if (archs.empty() == true) { archs.push_back(arch); - string dpkgcall = _config->Find("Dir::Bin::dpkg", "dpkg"); - std::vector<string> const dpkgoptions = _config->FindVector("DPkg::options"); - for (std::vector<string>::const_iterator o = dpkgoptions.begin(); - o != dpkgoptions.end(); ++o) - dpkgcall.append(" ").append(*o); - dpkgcall.append(" --print-foreign-architectures 2> /dev/null"); - FILE *dpkg = popen(dpkgcall.c_str(), "r"); + + // Generate the base argument list for dpkg + std::vector<const char *> Args; + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + { + string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); + size_t dpkgChrootLen = dpkgChrootDir.length(); + if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) { + if (dpkgChrootDir[dpkgChrootLen - 1] == '/') + --dpkgChrootLen; + Tmp = Tmp.substr(dpkgChrootLen); + } + } + Args.push_back(Tmp.c_str()); + + // Stick in any custom dpkg options + ::Configuration::Item const *Opts = _config->Tree("DPkg::Options"); + if (Opts != 0) { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + Args.push_back(Opts->Value.c_str()); + } + } + + Args.push_back("--print-foreign-architectures"); + Args.push_back(NULL); + + int external[2] = {-1, -1}; + if (pipe(external) != 0) + { + _error->WarningE("getArchitecture", "Can't create IPC pipe for dpkg --print-foreign-architectures"); + return archs; + } + + pid_t dpkgMultiArch = ExecFork(); + if (dpkgMultiArch == 0) { + close(external[0]); + std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); + if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0) + _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str()); + int const nullfd = open("/dev/null", O_RDONLY); + dup2(nullfd, STDIN_FILENO); + dup2(external[1], STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + execv(Args[0], (char**) &Args[0]); + _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!"); + _exit(100); + } + close(external[1]); + + FILE *dpkg = fdopen(external[0], "r"); char buf[1024]; if(dpkg != NULL) { - if (fgets(buf, sizeof(buf), dpkg) != NULL) { + while (fgets(buf, sizeof(buf), dpkg) != NULL) { char* arch = strtok(buf, " "); while (arch != NULL) { for (; isspace(*arch) != 0; ++arch); @@ -349,8 +397,9 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache arch = strtok(NULL, " "); } } - pclose(dpkg); + fclose(dpkg); } + ExecWait(dpkgMultiArch, "dpkg --print-foreign-architectures", true); return archs; } diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index e6a0fddb0..d5e018be9 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -207,7 +207,7 @@ class pkgCache::VerIterator : public Iterator<Version, VerIterator> { inline const char *VerStr() const {return S->VerStr == 0?0:Owner->StrP + S->VerStr;}; inline const char *Section() const {return S->Section == 0?0:Owner->StrP + S->Section;}; inline const char *Arch() const { - if (S->MultiArch == pkgCache::Version::All) + if ((S->MultiArch & pkgCache::Version::All) == pkgCache::Version::All) return "all"; return S->ParentPkg == 0?0:Owner->StrP + ParentPkg()->Arch; }; diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 0949ec223..36866a35a 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -185,8 +185,14 @@ string Configuration::FindFile(const char *Name,const char *Default) const } string val = Itm->Value; - while (Itm->Parent != 0 && Itm->Parent->Value.empty() == false) - { + while (Itm->Parent != 0) + { + if (Itm->Parent->Value.empty() == true) + { + Itm = Itm->Parent; + continue; + } + // Absolute if (val.length() >= 1 && val[0] == '/') break; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index b350973af..28898fc34 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -867,6 +867,7 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co else iFd = open(FileName.c_str(), fileflags, Perms); + this->FileName = FileName; if (iFd == -1 || OpenInternDescriptor(Mode, compressor) == false) { if (iFd != -1) @@ -877,7 +878,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co return _error->Errno("open",_("Could not open file %s"), FileName.c_str()); } - this->FileName = FileName; SetCloseExec(iFd,true); return true; } @@ -916,13 +916,13 @@ bool FileFd::OpenDescriptor(int Fd, unsigned int const Mode, APT::Configuration: d->openmode = Mode; Flags = (AutoClose) ? FileFd::AutoClose : 0; iFd = Fd; + this->FileName = ""; if (OpenInternDescriptor(Mode, compressor) == false) { if (AutoClose) close (iFd); return _error->Errno("gzdopen",_("Could not open file descriptor %d"), Fd); } - this->FileName = ""; return true; } bool FileFd::OpenInternDescriptor(unsigned int const Mode, APT::Configuration::Compressor const &compressor) @@ -1057,11 +1057,21 @@ bool FileFd::Read(void *To,unsigned long long Size,unsigned long long *Actual) else #endif Res = read(iFd,To,Size); - if (Res < 0 && errno == EINTR) - continue; + if (Res < 0) { + if (errno == EINTR) + continue; Flags |= Fail; +#if APT_USE_ZLIB + if (d->gz != NULL) + { + int err; + char const * const errmsg = gzerror(d->gz, &err); + if (err != Z_ERRNO) + return _error->Error("gzread: %s (%d: %s)", _("Read error"), err, errmsg); + } +#endif return _error->Errno("read",_("Read error")); } @@ -1337,6 +1347,7 @@ unsigned long long FileFd::Size() // gzopen in "direct" mode as well else if (d->gz && !gzdirect(d->gz) && size > 0) { + off_t const oldPos = lseek(iFd,0,SEEK_CUR); /* unfortunately zlib.h doesn't provide a gzsize(), so we have to do * this ourselves; the original (uncompressed) file size is the last 32 * bits of the file */ @@ -1354,8 +1365,9 @@ unsigned long long FileFd::Size() size = tmp_size; #endif - if (lseek(iFd, d->seekpos, SEEK_SET) < 0) + if (lseek(iFd, oldPos, SEEK_SET) < 0) return _error->Errno("lseek","Unable to seek in gzipped file"); + return size; } #endif @@ -1405,7 +1417,7 @@ bool FileFd::Close() #if APT_USE_ZLIB if (d != NULL && d->gz != NULL) { int const e = gzclose(d->gz); - // gzdopen() on empty files always fails with "buffer error" here, ignore that + // gzdclose() on empty files always fails with "buffer error" here, ignore that if (e != 0 && e != Z_BUF_ERROR) Res &= _error->Errno("close",_("Problem closing the gzip file %s"), FileName.c_str()); } else diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index a67ab3698..160718ea5 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -85,7 +85,7 @@ bool MMap::Map(FileFd &Fd) return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str()); Base = new unsigned char[iSize]; if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false) - return false; + return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str()); return true; } diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 4dc0baa50..51e896a4a 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -123,6 +123,18 @@ ionice(int PID) return ExecWait(Process, "ionice"); } +// dpkgChrootDirectory - chrooting for dpkg if needed /*{{{*/ +static void dpkgChrootDirectory() +{ + std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); + if (chrootDir == "/") + return; + std::cerr << "Chrooting into " << chrootDir << std::endl; + if (chroot(chrootDir.c_str()) != 0) + _exit(100); +} + /*}}}*/ + // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -328,15 +340,7 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) SetCloseExec(STDIN_FILENO,false); SetCloseExec(STDERR_FILENO,false); - if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") - { - std::cerr << "Chrooting into " - << _config->FindDir("DPkg::Chroot-Directory") - << std::endl; - if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0) - _exit(100); - } - + dpkgChrootDirectory(); const char *Args[4]; Args[0] = "/bin/sh"; Args[1] = "-c"; @@ -832,7 +836,17 @@ bool pkgDPkgPM::Go(int OutStatusFd) // Generate the base argument list for dpkg std::vector<const char *> Args; unsigned long StartSize = 0; - string const Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); + { + string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); + size_t dpkgChrootLen = dpkgChrootDir.length(); + if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) + { + if (dpkgChrootDir[dpkgChrootLen - 1] == '/') + --dpkgChrootLen; + Tmp = Tmp.substr(dpkgChrootLen); + } + } Args.push_back(Tmp.c_str()); StartSize += Tmp.length(); @@ -858,6 +872,12 @@ bool pkgDPkgPM::Go(int OutStatusFd) pid_t dpkgAssertMultiArch = ExecFork(); if (dpkgAssertMultiArch == 0) { + dpkgChrootDirectory(); + // redirect everything to the ultimate sink as we only need the exit-status + int const nullfd = open("/dev/null", O_RDONLY); + dup2(nullfd, STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); execv(Args[0], (char**) &Args[0]); _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!"); _exit(2); @@ -1085,7 +1105,14 @@ bool pkgDPkgPM::Go(int OutStatusFd) } else { - char * const fullname = strdup(I->Pkg.FullName(false).c_str()); + pkgCache::VerIterator PkgVer; + std::string name = I->Pkg.Name(); + if (Op == Item::Remove || Op == Item::Purge) + PkgVer = I->Pkg.CurrentVer(); + else + PkgVer = Cache[I->Pkg].InstVerIter(Cache); + name.append(":").append(PkgVer.Arch()); + char * const fullname = strdup(name.c_str()); Packages.push_back(fullname); ADDARG(fullname); } @@ -1190,14 +1217,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) } close(fd[0]); // close the read end of the pipe - if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") - { - std::cerr << "Chrooting into " - << _config->FindDir("DPkg::Chroot-Directory") - << std::endl; - if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0) - _exit(100); - } + dpkgChrootDirectory(); if (chdir(_config->FindDir("DPkg::Run-Directory","/").c_str()) != 0) _exit(100); diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 085159711..9449c7306 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -1240,19 +1240,36 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To) if (unlikely(Pkg.end() == true)) return; + APT::PackageList pkglist; + if (Pkg->CurrentVer != 0 && + (Pkg.CurrentVer()-> MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) + { + pkgCache::GrpIterator Grp = Pkg.Group(); + for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P)) + { + if (P->CurrentVer != 0) + pkglist.insert(P); + } + } + else + pkglist.insert(Pkg); + ActionGroup group(*this); - RemoveSizes(Pkg); - RemoveStates(Pkg); - - StateCache &P = PkgState[Pkg->ID]; - if (To == true) - P.iFlags |= ReInstall; - else - P.iFlags &= ~ReInstall; - - AddStates(Pkg); - AddSizes(Pkg); + for (APT::PackageList::const_iterator Pkg = pkglist.begin(); Pkg != pkglist.end(); ++Pkg) + { + RemoveSizes(Pkg); + RemoveStates(Pkg); + + StateCache &P = PkgState[Pkg->ID]; + if (To == true) + P.iFlags |= ReInstall; + else + P.iFlags &= ~ReInstall; + + AddStates(Pkg); + AddSizes(Pkg); + } } /*}}}*/ // DepCache::SetCandidateVersion - Change the candidate version /*{{{*/ diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc index c9d7a3024..a370f15a3 100644 --- a/apt-pkg/packagemanager.cc +++ b/apt-pkg/packagemanager.cc @@ -322,22 +322,22 @@ bool pkgPackageManager::ConfigureAll() only shown when debuging*/ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) { - // If this is true, only check and correct and dependancies without the Loop flag + // If this is true, only check and correct and dependencies without the Loop flag bool PkgLoop = List->IsFlag(Pkg,pkgOrderList::Loop); if (Debug) { VerIterator InstallVer = VerIterator(Cache,Cache[Pkg].InstallVer); clog << OutputInDepth(Depth) << "SmartConfigure " << Pkg.Name() << " (" << InstallVer.VerStr() << ")"; if (PkgLoop) - clog << " (Only Correct Dependancies)"; + clog << " (Only Correct Dependencies)"; clog << endl; } VerIterator const instVer = Cache[Pkg].InstVerIter(Cache); - /* Because of the ordered list, most dependancies should be unpacked, + /* Because of the ordered list, most dependencies should be unpacked, however if there is a loop (A depends on B, B depends on A) this will not - be the case, so check for dependancies before configuring. */ + be the case, so check for dependencies before configuring. */ bool Bad = false; for (DepIterator D = instVer.DependsList(); D.end() == false; ) @@ -424,7 +424,7 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth) if (Start==End) { if (Bad && Debug && List->IsFlag(DepPkg,pkgOrderList::Loop) == false) - std::clog << OutputInDepth(Depth) << "Could not satisfy dependancies for " << Pkg.Name() << std::endl; + std::clog << OutputInDepth(Depth) << "Could not satisfy dependencies for " << Pkg.Name() << std::endl; break; } else { Start++; @@ -529,7 +529,6 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg) List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States); return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge); - return true; } /*}}}*/ // PM::SmartUnPack - Install helper /*{{{*/ @@ -682,7 +681,13 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c VerIterator Ver(Cache,*I); PkgIterator BrokenPkg = Ver.ParentPkg(); VerIterator InstallVer(Cache,Cache[BrokenPkg].InstallVer); - + if (BrokenPkg.CurrentVer() != Ver) + { + if (Debug) + std::clog << OutputInDepth(Depth) << " Ignore not-installed version " << Ver.VerStr() << " of " << Pkg.FullName() << " for " << End << std::endl; + continue; + } + // Check if it needs to be unpacked if (List->IsFlag(BrokenPkg,pkgOrderList::InList) && Cache[BrokenPkg].Delete() == false && List->IsNow(BrokenPkg)) { @@ -733,7 +738,7 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States); - if (Immediate == true && instVer->MultiArch == pkgCache::Version::Same) + if (Immediate == true && (instVer->MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same) { /* Do lockstep M-A:same unpacking in two phases: First unpack all installed architectures, then the not installed. |