From 6085ab7488326cfed8f82e07eefcbc2dc40d4bea Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 12 Apr 2018 09:59:47 +0200 Subject: Support local files as arguments in show command Now that --with-source is supported in show we can go a little further and add the "syntactic sugar" of supporting deb-files on the commandline directly to give users an alternative to remembering dpkg -I for deb files & as a bonus apt also works on changes files. Most of the code churn is actually to deal with cases probably not too common in reality like mixing packages and deb-files on the commandline and getting the right order for these multiple records. Closes: 883206 --- apt-private/private-install.cc | 63 ++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'apt-private/private-install.cc') diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 4bb756b4f..f90e7097f 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -733,39 +733,54 @@ bool AddVolatileBinaryFile(pkgSourceList *const SL, PseudoPkg &&pkg, std::vector return true; } /*}}}*/ -std::vector GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector &), std::string const &pseudoArch)/*{{{*/ +static bool AddIfVolatile(pkgSourceList *const SL, std::vector &VolatileCmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector &), char const * const I, std::string const &pseudoArch)/*{{{*/ { - std::vector VolatileCmdL; - std::remove_if(CmdL.FileList + 1, CmdL.FileList + 1 + CmdL.FileSize(), [&](char const *const I) { - if (I != nullptr && (I[0] == '/' || (I[0] == '.' && (I[1] == '\0' || (I[1] == '.' && (I[2] == '\0' || I[2] == '/')) || I[1] == '/')))) + 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 { - PseudoPkg pkg(I, pseudoArch, "", SL->GetVolatileFiles().size()); - if (FileExists(I)) // this accepts directories and symlinks, too + 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; - } - 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 true; } - return false; + } + return false; +} + /*}}}*/ +std::vector GetAllPackagesAsPseudo(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector &), std::string const &pseudoArch)/*{{{*/ +{ + std::vector 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 GetPseudoPackages(pkgSourceList *const SL, CommandLine &CmdL, bool (*Add)(pkgSourceList *const, PseudoPkg &&, std::vector &), std::string const &pseudoArch)/*{{{*/ +{ + std::vector 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; } -- cgit v1.2.3