diff options
Diffstat (limited to 'apt-private')
-rw-r--r-- | apt-private/private-install.cc | 107 | ||||
-rw-r--r-- | apt-private/private-install.h | 18 | ||||
-rw-r--r-- | apt-private/private-search.cc | 9 | ||||
-rw-r--r-- | apt-private/private-show.cc | 250 | ||||
-rw-r--r-- | apt-private/private-show.h | 7 | ||||
-rw-r--r-- | apt-private/private-source.cc | 90 | ||||
-rw-r--r-- | apt-private/private-upgrade.cc | 3 |
7 files changed, 340 insertions, 144 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index e1beb21c6..f90e7097f 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -564,16 +564,16 @@ static const unsigned short MOD_INSTALL = 2; bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode) { - std::vector<std::string> VolatileCmdL; + std::vector<PseudoPkg> VolatileCmdL; return DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, UpgradeMode); } -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::string> &VolatileCmdL, CacheFile &Cache, int UpgradeMode) +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, int UpgradeMode) { std::map<unsigned short, APT::VersionSet> verset; std::set<std::string> UnknownPackages; return DoCacheManipulationFromCommandLine(CmdL, VolatileCmdL, Cache, verset, UpgradeMode, UnknownPackages); } -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::string> &VolatileCmdL, CacheFile &Cache, +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, std::map<unsigned short, APT::VersionSet> &verset, int UpgradeMode, std::set<std::string> &UnknownPackages) { // Enter the special broken fixing mode if the user specified arguments @@ -611,13 +611,18 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::stri for (auto const &I: VolatileCmdL) { - pkgCache::PkgIterator const P = Cache->FindPkg(I); + pkgCache::PkgIterator const P = Cache->FindPkg(I.name); if (P.end()) continue; // Set any version providing the .deb as the candidate. for (auto Prv = P.ProvidesList(); Prv.end() == false; Prv++) - Cache.GetDepCache()->SetCandidateVersion(Prv.OwnerVer()); + { + if (I.release.empty()) + Cache.GetDepCache()->SetCandidateVersion(Prv.OwnerVer()); + else + Cache.GetDepCache()->SetCandidateRelease(Prv.OwnerVer(), I.release); + } // via cacheset to have our usual virtual handling APT::VersionContainerInterface::FromPackage(&(verset[MOD_INSTALL]), Cache, P, APT::CacheSetHelper::CANDIDATE, helper); @@ -703,6 +708,83 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::stri return true; } /*}}}*/ +bool AddVolatileSourceFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL)/*{{{*/ +{ + auto const ext = flExtension(pkg.name); + if (ext != "dsc" && FileExists(pkg.name + "/debian/control") == false) + return false; + std::vector<std::string> files; + SL->AddVolatileFile(pkg.name, &files); + for (auto &&f: files) + VolatileCmdL.emplace_back(std::move(f), pkg.arch, pkg.release, pkg.index); + return true; + +} + /*}}}*/ +bool AddVolatileBinaryFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL)/*{{{*/ +{ + auto const ext = flExtension(pkg.name); + if (ext != "deb" && ext != "ddeb" && ext != "changes") + return false; + std::vector<std::string> files; + SL->AddVolatileFile(pkg.name, &files); + for (auto &&f: files) + VolatileCmdL.emplace_back(std::move(f), pkg.arch, pkg.release, pkg.index); + return true; +} + /*}}}*/ +static bool AddIfVolatile(pkgSourceList *const SL, std::vector<PseudoPkg> &VolatileCmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), char const * const I, std::string const &pseudoArch)/*{{{*/ +{ + if (I != nullptr && (I[0] == '/' || (I[0] == '.' && (I[1] == '\0' || (I[1] == '.' && (I[2] == '\0' || I[2] == '/')) || I[1] == '/')))) + { + PseudoPkg pkg(I, pseudoArch, "", SL->GetVolatileFiles().size()); + if (FileExists(I)) // this accepts directories and symlinks, too + { + if (Add(SL, std::move(pkg), VolatileCmdL)) + ; + else + _error->Error(_("Unsupported file %s given on commandline"), I); + return true; + } + else + { + auto const found = pkg.name.rfind("/"); + if (found == pkg.name.find("/")) + _error->Error(_("Unsupported file %s given on commandline"), I); + else + { + pkg.release = pkg.name.substr(found + 1); + pkg.name.erase(found); + if (Add(SL, std::move(pkg), VolatileCmdL)) + ; + else + _error->Error(_("Unsupported file %s given on commandline"), I); + } + return true; + } + } + return false; +} + /*}}}*/ +std::vector<PseudoPkg> GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch)/*{{{*/ +{ + std::vector<PseudoPkg> PkgCmdL; + std::for_each(CmdL.FileList + 1, CmdL.FileList + CmdL.FileSize(), [&](char const *const I) { + if (AddIfVolatile(SL, PkgCmdL, Add, I, pseudoArch) == false) + PkgCmdL.emplace_back(I, pseudoArch, "", -1); + }); + return PkgCmdL; +} + /*}}}*/ +std::vector<PseudoPkg> GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch)/*{{{*/ +{ + std::vector<PseudoPkg> VolatileCmdL; + std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const *const I) { + return AddIfVolatile(SL, VolatileCmdL, Add, I, pseudoArch); + }); + return VolatileCmdL; +} + /*}}}*/ // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ @@ -721,8 +803,7 @@ struct PkgIsExtraInstalled { bool DoInstall(CommandLine &CmdL) { CacheFile Cache; - std::vector<std::string> VolatileCmdL; - Cache.GetSourceList()->AddVolatileFiles(CmdL, &VolatileCmdL); + auto VolatileCmdL = GetPseudoPackages(Cache.GetSourceList(), CmdL, AddVolatileBinaryFile, ""); // then open the cache if (Cache.OpenForInstall() == false || @@ -945,13 +1026,21 @@ bool TryToInstall::propergateReleaseCandiateSwitching(std::list<std::pair<pkgCac c != Changed.end(); ++c) { if (c->second.end() == true) + { + auto const pkgname = c->first.ParentPkg().FullName(true); + if (APT::String::Startswith(pkgname, "builddeps:")) + continue; ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"), - c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str()); + c->first.VerStr(), c->first.RelStr().c_str(), pkgname.c_str()); + } else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group) { + auto pkgname = c->second.ParentPkg().FullName(true); + if (APT::String::Startswith(pkgname, "builddeps:")) + pkgname.replace(0, strlen("builddeps"), "src"); pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache); ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(), - V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str()); + V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), pkgname.c_str()); } } return Success; diff --git a/apt-private/private-install.h b/apt-private/private-install.h index 2d27756c9..39a040e7d 100644 --- a/apt-private/private-install.h +++ b/apt-private/private-install.h @@ -17,9 +17,23 @@ class pkgProblemResolver; APT_PUBLIC bool DoInstall(CommandLine &Cmd); -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::string> &VolatileCmdL, CacheFile &Cache, +struct PseudoPkg +{ + std::string name; + std::string arch; + std::string release; + ssize_t index; + PseudoPkg(std::string const &n, std::string const &a, std::string const &r) : name(n), arch(a), release(r), index(-1) {} + PseudoPkg(std::string const &n, std::string const &a, std::string const &r, ssize_t i) : name(n), arch(a), release(r), index(i) {} +}; +std::vector<PseudoPkg> GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch); +std::vector<PseudoPkg> GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector<PseudoPkg> &), std::string const &pseudoArch); +bool AddVolatileBinaryFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL); +bool AddVolatileSourceFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector<PseudoPkg> &VolatileCmdL); + +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, std::map<unsigned short, APT::VersionSet> &verset, int UpgradeMode, std::set<std::string> &UnknownPackages); -bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<std::string> &VolatileCmdL, CacheFile &Cache, int UpgradeMode); +bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg> &VolatileCmdL, CacheFile &Cache, int UpgradeMode); bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode); APT_PUBLIC bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true, diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc index 52a52e522..de1b19758 100644 --- a/apt-private/private-search.cc +++ b/apt-private/private-search.cc @@ -316,7 +316,14 @@ static bool Search(CommandLine &CmdL) if (matchedAll == true) { if (ShowFull == true) - DisplayRecordV1(CacheFile, J->V, std::cout); + { + pkgCache::VerFileIterator Vf; + auto &Parser = LookupParser(Recs, J->V, Vf); + char const *Start, *Stop; + Parser.GetRec(Start, Stop); + size_t const Length = Stop - Start; + DisplayRecordV1(CacheFile, Recs, J->V, Vf, Start, Length, std::cout); + } else printf("%s - %s\n",P.Name().c_str(),P.ShortDesc().c_str()); } diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index afe448a33..15c05d420 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -20,6 +20,7 @@ #include <apt-private/private-cacheset.h> #include <apt-private/private-output.h> +#include <apt-private/private-install.h> #include <apt-private/private-show.h> #include <ostream> @@ -30,35 +31,23 @@ #include <apti18n.h> /*}}}*/ -static bool OpenPackagesFile(pkgCacheFile &CacheFile, pkgCache::VerIterator const &V,/*{{{*/ - FileFd &PkgF, pkgCache::VerFileIterator &Vf) +pkgRecords::Parser &LookupParser(pkgRecords &Recs, pkgCache::VerIterator const &V, pkgCache::VerFileIterator &Vf) /*{{{*/ { - pkgCache const * const Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - - // Find an appropriate file Vf = V.FileList(); for (; Vf.end() == false; ++Vf) if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0) break; if (Vf.end() == true) Vf = V.FileList(); - - // Check and load the package list file - pkgCache::PkgFileIterator I = Vf.File(); - if (I.IsOk() == false) - return _error->Error(_("Package file %s is out of sync."),I.FileName()); - - // Read the record - return PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension); + return Recs.Lookup(Vf); } /*}}}*/ -static APT_PURE unsigned char const* skipDescriptionFields(unsigned char const * DescP)/*{{{*/ +static APT_PURE char const *skipDescriptionFields(char const *DescP, size_t const Length) /*{{{*/ { + auto const backup = DescP; char const * const TagName = "\nDescription"; size_t const TagLen = strlen(TagName); - while ((DescP = (unsigned char*)strchr((char*)DescP, '\n')) != NULL) + while ((DescP = static_cast<char const *>(memchr(DescP, '\n', Length - (DescP - backup)))) != nullptr) { if (DescP[1] == ' ') DescP += 2; @@ -72,114 +61,126 @@ static APT_PURE unsigned char const* skipDescriptionFields(unsigned char const * return DescP; } /*}}}*/ -bool DisplayRecordV1(pkgCacheFile &CacheFile, pkgCache::VerIterator const &V,/*{{{*/ - std::ostream &out) +static APT_PURE char const *findDescriptionField(char const *DescP, size_t const Length) /*{{{*/ { - FileFd PkgF; - pkgCache::VerFileIterator Vf; - if (OpenPackagesFile(CacheFile, V, PkgF, Vf) == false) - return false; + auto const backup = DescP; + char const * const TagName = "\nDescription"; + size_t const TagLen = strlen(TagName); + while ((DescP = static_cast<char const *>(memchr(DescP, '\n', Length - (DescP - backup)))) != nullptr) + { + if (strncmp(DescP, TagName, TagLen) == 0) + break; + else + ++DescP; + } + if (DescP != nullptr) + ++DescP; + return DescP; +} + /*}}}*/ - pkgCache * const Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) +bool DisplayRecordV1(pkgCacheFile &, pkgRecords &Recs, /*{{{*/ + pkgCache::VerIterator const &V, pkgCache::VerFileIterator const &, + char const *Buffer, size_t Length, std::ostream &out) +{ + if (unlikely(Length == 0)) return false; - // Read the record (and ensure that it ends with a newline and NUL) - unsigned char *Buffer = new unsigned char[Cache->HeaderP->MaxVerFileSize+2]; - Buffer[Vf->Size] = '\n'; - Buffer[Vf->Size+1] = '\0'; - if (PkgF.Seek(Vf->Offset) == false || - PkgF.Read(Buffer,Vf->Size) == false) + auto const Desc = V.TranslatedDescription(); + if (Desc.end()) { - delete [] Buffer; - return false; + // we have no translation output whatever we have got + return FileFd::Write(STDOUT_FILENO, Buffer, Length); } // Get a pointer to start of Description field - const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "\nDescription"); - if (DescP != NULL) - ++DescP; - else - DescP = Buffer + Vf->Size; + char const *DescP = findDescriptionField(Buffer, Length); + if (DescP == nullptr) + DescP = Buffer + Length; // Write all but Description - size_t const length = DescP - Buffer; - if (length != 0 && FileFd::Write(STDOUT_FILENO, Buffer, length) == false) - { - delete [] Buffer; + size_t const untilDesc = DescP - Buffer; + if (untilDesc != 0 && FileFd::Write(STDOUT_FILENO, Buffer, untilDesc) == false) return false; - } // Show the right description - pkgRecords Recs(*Cache); - pkgCache::DescIterator Desc = V.TranslatedDescription(); - if (Desc.end() == false) - { - pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); - out << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc(); - out << std::endl << "Description-md5: " << Desc.md5() << std::endl; + char desctag[50]; + auto const langcode = Desc.LanguageCode(); + if (strcmp(langcode, "") == 0) + strcpy(desctag, "\nDescription"); + else + snprintf(desctag, sizeof(desctag), "\nDescription-%s", langcode); - // Find the first field after the description (if there is any) - DescP = skipDescriptionFields(DescP); + out << desctag + 1 << ": "; + auto const Df = Desc.FileList(); + if (Df.end() == false) + { + pkgRecords::Parser &P = Recs.Lookup(Df); + out << P.LongDesc(); } - // else we have no translation, so we found a lonely Description-md5 -> don't skip it + + out << std::endl << "Description-md5: " << Desc.md5() << std::endl; + + // Find the first field after the description (if there is any) + DescP = skipDescriptionFields(DescP, Length - (DescP - Buffer)); // write the rest of the buffer, but skip mixed in Descriptions* fields - while (DescP != NULL) + while (DescP != nullptr) { - const unsigned char * const Start = DescP; - const unsigned char *End = (unsigned char*)strstr((char*)DescP, "\nDescription"); - if (End == NULL) + char const *const Start = DescP; + char const *End = findDescriptionField(DescP, Length - (DescP - Buffer)); + if (End == nullptr) { - End = &Buffer[Vf->Size]; - DescP = NULL; + DescP = nullptr; + End = Buffer + Length - 1; + size_t endings = 0; + while (*End == '\n') + { + --End; + if (*End == '\r') + --End; + ++endings; + } + if (endings >= 1) + { + ++End; + if (*End == '\r') + ++End; + } + ++End; } else - { - ++End; // get the newline into the output - DescP = skipDescriptionFields(End + strlen("Description")); - } + DescP = skipDescriptionFields(End + strlen("Description"), Length - (End - Buffer)); + size_t const length = End - Start; if (length != 0 && FileFd::Write(STDOUT_FILENO, Start, length) == false) - { - delete [] Buffer; return false; - } } // write a final newline after the last field out << std::endl; - delete [] Buffer; return true; } /*}}}*/ -static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgCache::VerIterator const &V,/*{{{*/ - std::ostream &out) +static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgRecords &Recs, /*{{{*/ + pkgCache::VerIterator const &V, pkgCache::VerFileIterator const &Vf, + char const *Buffer, size_t const Length, std::ostream &out) { - FileFd PkgF; - pkgCache::VerFileIterator Vf; - if (OpenPackagesFile(CacheFile, V, PkgF, Vf) == false) - return false; - // Check and load the package list file pkgCache::PkgFileIterator I = Vf.File(); - if (I.IsOk() == false) - return _error->Error(_("Package file %s is out of sync."),I.FileName()); // find matching sources.list metaindex pkgSourceList *SrcList = CacheFile.GetSourceList(); pkgIndexFile *Index; if (SrcList->FindIndex(I, Index) == false && _system->FindIndex(I, Index) == false) - return _error->Error("Can not find indexfile for Package %s (%s)", - V.ParentPkg().Name(), V.VerStr()); + return _error->Error("Can not find indexfile for Package %s (%s)", + V.ParentPkg().Name(), V.VerStr()); std::string source_index_file = Index->Describe(true); // Read the record pkgTagSection Tags; - pkgTagFile TagF(&PkgF); - - if (TagF.Jump(Tags, V.FileList()->Offset) == false) + if (Tags.Scan(Buffer, Length, true) == false) return _error->Error("Internal Error, Unable to parse a package record"); // make size nice @@ -234,10 +235,6 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgCache::VerIterator const return _error->Error("Internal Error, Unable to parse a package record"); // write the description - pkgCache * const Cache = CacheFile.GetPkgCache(); - if (unlikely(Cache == NULL)) - return false; - pkgRecords Recs(*Cache); // FIXME: show (optionally) all available translations(?) pkgCache::DescIterator Desc = V.TranslatedDescription(); if (Desc.end() == false) @@ -245,7 +242,7 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgCache::VerIterator const pkgRecords::Parser &P = Recs.Lookup(Desc.FileList()); out << "Description: " << P.LongDesc(); } - + // write a final newline (after the description) out << std::endl << std::endl; @@ -255,26 +252,93 @@ static bool DisplayRecordV2(pkgCacheFile &CacheFile, pkgCache::VerIterator const bool ShowPackage(CommandLine &CmdL) /*{{{*/ { pkgCacheFile CacheFile; + auto VolatileCmdL = GetAllPackagesAsPseudo(CacheFile.GetSourceList(), CmdL, AddVolatileBinaryFile, ""); + + if (unlikely(CacheFile.GetPkgCache() == nullptr)) + return false; CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); APT::CacheSetHelper::VerSelector const select = _config->FindB("APT::Cache::AllVersions", true) ? APT::CacheSetHelper::ALL : APT::CacheSetHelper::CANDIDATE; if (select == APT::CacheSetHelper::CANDIDATE && CacheFile.GetDepCache() == nullptr) return false; - APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); + + APT::VersionList verset; + size_t normalPackages = 0; + for (auto const &I: VolatileCmdL) + { + if (I.index == -1) + { + APT::VersionContainerInterface::FromString(&verset, CacheFile, I.name, select, helper); + ++normalPackages; + } + else + { + if (select != APT::CacheSetHelper::CANDIDATE && unlikely(CacheFile.GetDepCache() == nullptr)) + return false; + pkgCache::PkgIterator const P = CacheFile->FindPkg(I.name); + if (unlikely(P.end())) + continue; + + // Set any version providing the .deb as the candidate. + for (auto Prv = P.ProvidesList(); Prv.end() == false; ++Prv) + { + if (I.release.empty()) + CacheFile->SetCandidateVersion(Prv.OwnerVer()); + else + CacheFile->SetCandidateRelease(Prv.OwnerVer(), I.release); + + // via cacheset to have our usual handling + APT::VersionContainerInterface::FromPackage(&verset, CacheFile, Prv.OwnerPkg(), APT::CacheSetHelper::CANDIDATE, helper); + } + } + } + int const ShowVersion = _config->FindI("APT::Cache::Show::Version", 1); + pkgRecords Recs(CacheFile); for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) + { + pkgCache::VerFileIterator Vf; + auto &Parser = LookupParser(Recs, Ver, Vf); + char const *Start, *Stop; + Parser.GetRec(Start, Stop); + size_t const Length = Stop - Start; + if (ShowVersion <= 1) { - if (DisplayRecordV1(CacheFile, Ver, std::cout) == false) + if (DisplayRecordV1(CacheFile, Recs, Ver, Vf, Start, Length, std::cout) == false) return false; } - else - if (DisplayRecordV2(CacheFile, Ver, c1out) == false) - return false; + else if (DisplayRecordV2(CacheFile, Recs, Ver, Vf, Start, Length + 1, c1out) == false) + return false; + } - if (select == APT::CacheSetHelper::CANDIDATE) + if (select == APT::CacheSetHelper::CANDIDATE && normalPackages != 0) { - APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::ALL, helper); + APT::VersionList verset_all; + for (auto const &I: VolatileCmdL) + { + if (I.index == -1) + APT::VersionContainerInterface::FromString(&verset_all, CacheFile, I.name, APT::CacheSetHelper::ALL, helper); + else + { + pkgCache::PkgIterator const P = CacheFile->FindPkg(I.name); + if (unlikely(P.end())) + continue; + + // Set any version providing the .deb as the candidate. + for (auto Prv = P.ProvidesList(); Prv.end() == false; ++Prv) + { + if (I.release.empty()) + CacheFile->SetCandidateVersion(Prv.OwnerVer()); + else + CacheFile->SetCandidateRelease(Prv.OwnerVer(), I.release); + + // via cacheset to have our usual virtual handling + APT::VersionContainerInterface::FromPackage(&verset_all, CacheFile, Prv.OwnerPkg(), APT::CacheSetHelper::CANDIDATE, helper); + } + } + } + int const records = verset_all.size() - verset.size(); if (records > 0) _error->Notice(P_("There is %i additional record. Please use the '-a' switch to see it", "There are %i additional records. Please use the '-a' switch to see them.", records), records); diff --git a/apt-private/private-show.h b/apt-private/private-show.h index e48979c2c..9e5fa995f 100644 --- a/apt-private/private-show.h +++ b/apt-private/private-show.h @@ -3,6 +3,7 @@ #include <apt-pkg/macros.h> #include <apt-pkg/pkgcache.h> +#include <apt-pkg/pkgrecords.h> #include <iostream> @@ -10,8 +11,12 @@ class CommandLine; class pkgCacheFile; APT_PUBLIC bool ShowPackage(CommandLine &CmdL); -APT_PUBLIC bool DisplayRecordV1(pkgCacheFile &CacheFile, pkgCache::VerIterator const &V, std::ostream &out); APT_PUBLIC bool ShowSrcPackage(CommandLine &CmdL); APT_PUBLIC bool Policy(CommandLine &CmdL); +pkgRecords::Parser &LookupParser(pkgRecords &Recs, pkgCache::VerIterator const &V, pkgCache::VerFileIterator &Vf); +bool DisplayRecordV1(pkgCacheFile &CacheFile, pkgRecords &Recs, + pkgCache::VerIterator const &V, pkgCache::VerFileIterator const &Vf, + char const *Buffer, size_t const Length, std::ostream &out); + #endif diff --git a/apt-private/private-source.cc b/apt-private/private-source.cc index 32651cfdb..c8a48a74a 100644 --- a/apt-private/private-source.cc +++ b/apt-private/private-source.cc @@ -636,15 +636,6 @@ static void WriteBuildDependencyPackage(std::ostringstream &buildDepsPkgFile, } bool DoBuildDep(CommandLine &CmdL) { - CacheFile Cache; - std::vector<std::string> VolatileCmdL; - Cache.GetSourceList()->AddVolatileFiles(CmdL, &VolatileCmdL); - - _config->Set("APT::Install-Recommends", false); - - if (CmdL.FileSize() <= 1 && VolatileCmdL.empty()) - return _error->Error(_("Must specify at least one package to check builddeps for")); - bool StripMultiArch; std::string hostArch = _config->Find("APT::Get::Host-Architecture"); if (hostArch.empty() == false) @@ -656,9 +647,19 @@ bool DoBuildDep(CommandLine &CmdL) } else StripMultiArch = true; + auto const nativeArch = _config->Find("APT::Architecture"); + std::string const pseudoArch = hostArch.empty() ? nativeArch : hostArch; + + CacheFile Cache; + auto VolatileCmdL = GetPseudoPackages(Cache.GetSourceList(), CmdL, AddVolatileSourceFile, pseudoArch); + + _config->Set("APT::Install-Recommends", false); + + if (CmdL.FileSize() <= 1 && VolatileCmdL.empty()) + return _error->Error(_("Must specify at least one package to check builddeps for")); std::ostringstream buildDepsPkgFile; - std::vector<std::pair<std::string,std::string>> pseudoPkgs; + std::vector<PseudoPkg> pseudoPkgs; // deal with the build essentials first { std::vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps; @@ -673,43 +674,42 @@ bool DoBuildDep(CommandLine &CmdL) BuildDeps.push_back(rec); } std::string const pseudo = "builddeps:essentials"; - std::string const nativeArch = _config->Find("APT::Architecture"); WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, nativeArch, BuildDeps); - pseudoPkgs.emplace_back(pseudo, nativeArch); + pseudoPkgs.emplace_back(pseudo, nativeArch, ""); } // Read the source list if (Cache.BuildSourceList() == false) return false; pkgSourceList *List = Cache.GetSourceList(); - std::string const pseudoArch = hostArch.empty() ? _config->Find("APT::Architecture") : hostArch; - // FIXME: Avoid volatile sources == cmdline assumption { auto const VolatileSources = List->GetVolatileFiles(); - if (VolatileSources.size() == VolatileCmdL.size()) + for (auto &&pkg : VolatileCmdL) { - for (size_t i = 0; i < VolatileSources.size(); ++i) + if (unlikely(pkg.index == -1)) { - auto const Src = VolatileCmdL[i]; - if (DirectoryExists(Src)) - ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), Src.c_str()); - else - ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), Src.c_str()); - std::unique_ptr<pkgSrcRecords::Parser> Last(VolatileSources[i]->CreateSrcParser()); - if (Last == nullptr) - return _error->Error(_("Unable to find a source package for %s"), Src.c_str()); - - std::string const pseudo = std::string("builddeps:") + Src; - WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, pseudoArch, - GetBuildDeps(Last.get(), Src.c_str(), StripMultiArch, hostArch)); - pseudoPkgs.emplace_back(pseudo, pseudoArch); + _error->Error(_("Unable to find a source package for %s"), pkg.name.c_str()); + continue; } + if (DirectoryExists(pkg.name)) + ioprintf(c1out, _("Note, using directory '%s' to get the build dependencies\n"), pkg.name.c_str()); + else + ioprintf(c1out, _("Note, using file '%s' to get the build dependencies\n"), pkg.name.c_str()); + std::unique_ptr<pkgSrcRecords::Parser> Last(VolatileSources[pkg.index]->CreateSrcParser()); + if (Last == nullptr) + { + _error->Error(_("Unable to find a source package for %s"), pkg.name.c_str()); + continue; + } + + auto pseudo = std::string("builddeps:") + pkg.name; + WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, pseudoArch, + GetBuildDeps(Last.get(), pkg.name.c_str(), StripMultiArch, hostArch)); + pkg.name = std::move(pseudo); + pseudoPkgs.push_back(std::move(pkg)); } - else - return _error->Error("Implementation error: Volatile sources (%lu) and" - "commandline elements (%lu) do not match!", VolatileSources.size(), - VolatileCmdL.size()); + VolatileCmdL.clear(); } bool const WantLock = _config->FindB("APT::Get::Print-URIs", false) == false; @@ -731,7 +731,13 @@ bool DoBuildDep(CommandLine &CmdL) std::string const pseudo = std::string("builddeps:") + Src; WriteBuildDependencyPackage(buildDepsPkgFile, pseudo, pseudoArch, GetBuildDeps(Last, Src.c_str(), StripMultiArch, hostArch)); - pseudoPkgs.emplace_back(pseudo, pseudoArch); + std::string reltag = *I; + size_t found = reltag.find_last_of("/"); + if (found == std::string::npos) + reltag.clear(); + else + reltag.erase(0, found + 1); + pseudoPkgs.emplace_back(pseudo, pseudoArch, std::move(reltag)); } } @@ -745,12 +751,24 @@ bool DoBuildDep(CommandLine &CmdL) { pkgDepCache::ActionGroup group(Cache); TryToInstall InstallAction(Cache, &Fix, false); + std::list<std::pair<pkgCache::VerIterator, std::string>> candSwitch; + for (auto const &pkg: pseudoPkgs) + { + pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.name, pkg.arch); + if (Pkg.end()) + continue; + if (pkg.release.empty()) + Cache->SetCandidateVersion(Pkg.VersionList()); + else + candSwitch.emplace_back(Pkg.VersionList(), pkg.release); + } + if (candSwitch.empty() == false) + InstallAction.propergateReleaseCandiateSwitching(candSwitch, c0out); for (auto const &pkg: pseudoPkgs) { - pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.first, pkg.second); + pkgCache::PkgIterator const Pkg = Cache->FindPkg(pkg.name, pkg.arch); if (Pkg.end()) continue; - Cache->SetCandidateVersion(Pkg.VersionList()); InstallAction(Cache[Pkg].CandidateVerIter(Cache)); removeAgain.push_back(Pkg); } diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc index 989f6b0c1..aeaf5066b 100644 --- a/apt-private/private-upgrade.cc +++ b/apt-private/private-upgrade.cc @@ -19,8 +19,7 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags) { CacheFile Cache; - std::vector<std::string> VolatileCmdL; - Cache.GetSourceList()->AddVolatileFiles(CmdL, &VolatileCmdL); + auto VolatileCmdL = GetPseudoPackages(Cache.GetSourceList(), CmdL, AddVolatileBinaryFile, ""); if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false) return false; |