]> git.saurik.com Git - apt.git/commitdiff
add --with-source option and Packages/Sources support
authorDavid Kalnischkies <david@kalnischkies.de>
Tue, 16 Aug 2016 18:08:29 +0000 (20:08 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 17 Aug 2016 12:12:25 +0000 (14:12 +0200)
We support "./foobar.deb" as a way to install a deb file directly.
Recently .changes files were added. This highlights a problem as you
can't add the changes file without also trying to install all of them.
Now, it could also be handy to add entire Packages/Sources files to
perhaps get a bunch of packages in without installing them all
implicitly.

This commit introduces --with-source which allows to add *.deb, *.changes,
*.dsc, source-dirs, Packages & Sources files (the later can also be
compressed) without also installing them.

apt-pkg/deb/debindexfile.cc
apt-pkg/indexfile.cc
apt-pkg/sourcelist.cc
apt-private/private-cmndline.cc
doc/apt-cache.8.xml
doc/apt-get.8.xml
test/integration/test-apt-get-install-deb
test/integration/test-apt-key-used-in-maintainerscript

index 6a23b2c00ae57b96881857110f6df6a756abee1f..65bd3e6eefd6320614b1ac133ba426bad40d31b7 100644 (file)
@@ -80,7 +80,11 @@ debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted
 std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const
 {
    std::string Res = Target.Description;
-   Res.erase(Target.Description.rfind(' '));
+   {
+      auto const space = Target.Description.rfind(' ');
+      if (space != std::string::npos)
+        Res.erase(space);
+   }
 
    Res += " ";
    Res += Ver.ParentPkg().Name();
index b1435d32c168f44d373559757909004d2f103e5f..934943205ae6722af43d011fda57bc9bfd4ad68b 100644 (file)
@@ -151,7 +151,13 @@ std::string IndexTarget::Option(OptionKeys const EnumKey) const            /*{{{*/
       APT_CASE(ALLOW_WEAK);
       APT_CASE(ALLOW_DOWNGRADE_TO_INSECURE);
 #undef APT_CASE
-      case FILENAME: return _config->FindDir("Dir::State::lists") + URItoFileName(URI);
+      case FILENAME:
+      {
+        auto const M = Options.find("FILENAME");
+        if (M == Options.end())
+           return _config->FindDir("Dir::State::lists") + URItoFileName(URI);
+        return M->second;
+      }
       case EXISTING_FILENAME:
         std::string const filename = Option(FILENAME);
         std::vector<std::string> const types = VectorizeString(Option(COMPRESSIONTYPES), ' ');
index 00053958275cb7d5c5042da4e59604ccc0b13935..f4a84cc9b7bf6850c49bd5bd25c41074616e484c 100644 (file)
@@ -328,6 +328,9 @@ bool pkgSourceList::ReadMainList()
       // Only warn if there is no sources.list file.
       _error->WarningE("RealFileExists", _("Unable to read %s"), Main.c_str());
 
+   for (auto && file: _config->FindVector("APT::Sources::With"))
+      Res &= AddVolatileFile(file, nullptr);
+
    return Res;
 }
                                                                        /*}}}*/
@@ -544,6 +547,22 @@ void pkgSourceList::AddVolatileFile(pkgIndexFile * const File)             /*{{{*/
       VolatileFiles.push_back(File);
 }
                                                                        /*}}}*/
+static bool fileNameMatches(std::string const &filename, std::string const &idxtype)/*{{{*/
+{
+   for (auto && type: APT::Configuration::getCompressionTypes())
+   {
+      if (type == "uncompressed")
+      {
+        if (filename == idxtype || APT::String::Endswith(filename, '_' + idxtype))
+           return true;
+      }
+      else if (filename == idxtype + '.' + type ||
+           APT::String::Endswith(filename, '_' + idxtype + '.' + type))
+        return true;
+   }
+   return false;
+}
+                                                                       /*}}}*/
 bool pkgSourceList::AddVolatileFile(std::string const &File, std::vector<std::string> * const VolatileCmdL)/*{{{*/
 {
    // Note: FileExists matches directories and links, too!
@@ -574,7 +593,20 @@ bool pkgSourceList::AddVolatileFile(std::string const &File, std::vector<std::st
       return true;
    }
    else
-      return false;
+   {
+      auto const filename = flNotDir(File);
+      auto const Target = IndexTarget(File, filename, File, "file:" + File, false, true, {
+        { "FILENAME", File },
+        { "REPO_URI", "file:" + flAbsPath(flNotFile(File)) + '/' },
+        { "COMPONENT", "volatile-packages-file" },
+      });
+      if (fileNameMatches(filename, "Packages"))
+        AddVolatileFile(new debPackagesIndex(Target, true));
+      else if (fileNameMatches(filename, "Sources"))
+        AddVolatileFile(new debSourcesIndex(Target, true));
+      else
+        return false;
+   }
 
    if (VolatileCmdL != nullptr)
       VolatileCmdL->push_back(File);
index feb8d67a9f99355bde5bbf451898f44790ebddfc..a890aafab8f17df261b4be4b41a5e04bd704f490 100644 (file)
@@ -96,6 +96,7 @@ static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char cons
 
    addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg);
    addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg);
+   addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg);
 
    return found_something;
 }
@@ -275,6 +276,7 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const
    addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean);
    addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean);
    addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
+   addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg);
 
    return found_something;
 }
@@ -307,6 +309,7 @@ static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const
       addArg('s',"dry-run","APT::Mark::Simulate",0);
       addArg('s',"no-act","APT::Mark::Simulate",0);
    }
+   addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg);
 
    return true;
 }
@@ -340,6 +343,8 @@ static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * c
    else
       return false;
 
+   addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg);
+
    return true;
 }
                                                                        /*}}}*/
index 4e2de26bc0a69f52794ff8c46eff921b012eab6d..66f608b135c957258c29210fbcf0a4e7859f8643 100644 (file)
@@ -350,6 +350,21 @@ Reverse Provides:
       Configuration Item: <literal>APT::Cache::Installed</literal>.</para></listitem>
       </varlistentry>
 
+      <varlistentry><term><option>--with-source</option> <option>&synopsis-param-filename;</option></term>
+      <listitem><para>
+      Adds the given file as a source for metadata. Can be repeated to add multiple files.
+      Supported are currently <literal>*.deb</literal>, <literal>*.dsc</literal>,
+      <literal>*.changes</literal>, <literal>Sources</literal> and
+      <literal>Packages</literal> files as well as source package directories.
+      Files are matched based on their name only, not their content!</para>
+      <para><literal>Sources</literal> and <literal>Packages</literal> can be compressed in any
+      format apt supports as long as they have the correct extension. If you need to store
+      multiple of these files in one directory you can prefix a name of your choice with the
+      last character being an underscore ("<literal>_</literal>"). Example: my.example_Packages.xz</para>
+      <para>Note that these sources are treated as trusted (see &apt-secure;).
+      Configuration Item: <literal>APT::Sources::With</literal>.</para></listitem>
+      </varlistentry>
+
      &apt-commonoptions;
      
    </variablelist>
index 20555b77e43d672217f618b7adbc3c8822046609..074262595c300a5d31511c468405241a6c2eff19 100644 (file)
      README.progress-reporting in the apt doc directory.
      Configuration Item: <literal>Dpkg::Progress</literal> and <literal>Dpkg::Progress-Fancy</literal>.</para></listitem>
      </varlistentry>
-    
+
+     <varlistentry><term><option>--with-source</option> <option>&synopsis-param-filename;</option></term>
+     <listitem><para>
+     Adds the given file as a source for metadata. Can be repeated to add multiple files.
+     See <option>--with-source</option> description in &apt-cache; for further details.
+     </para></listitem>
+     </varlistentry>
 
      &apt-commonoptions;
      
index 3aacc301dcceef5722eddc9546ab95f7d6651a3e..5f2877dfd17b69794ee8081165a96600d04fd4d1 100755 (executable)
@@ -64,6 +64,23 @@ Remv foo:i386 [1.0]
 Inst foo (1.0 local-deb [amd64])
 Conf foo (1.0 local-deb [amd64])" aptget install ./incoming/foo_1.0_amd64.deb -s
 
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Reading state information...
+0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' aptget install --with-source ./incoming/foo_1.0_amd64.deb -s
+
+testsuccessequal 'Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages will be REMOVED:
+  foo:i386
+The following NEW packages will be installed:
+  foo
+0 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv foo:i386 [1.0]
+Inst foo (1.0 local-deb [amd64])
+Conf foo (1.0 local-deb [amd64])' aptget install --with-source ./incoming/foo_1.0_amd64.deb foo -s
+
 # Check that installing the local deb works if it is not the candidate
 echo "Package: foo
 Pin: version 1.0
@@ -133,3 +150,21 @@ fi
 sed -i -e '/^Depends: foo/ d' rootdir/var/lib/dpkg/status
 testsuccess aptget install -y ./incoming/pkg-as-it-should-be_0_all.deb
 testfailure grep 'is already the newest version' rootdir/tmp/testsuccess.output
+testsuccess apt purge -y pkg-as-it-should-be
+
+echo "Package: pkg-as-it-should-be
+Architecture: all
+Version: 0
+Installed-Size: 2903
+Filename: incoming/pkg-as-it-should-be_0_all.deb
+Size: $(stat -c %s incoming/pkg-as-it-should-be_0_all.deb)
+SHA256: $(sha256sum incoming/pkg-as-it-should-be_0_all.deb | cut -d' ' -f 1)
+" > Packages
+testdpkgnotinstalled 'pkg-as-it-should-be'
+testnopackage pkg-as-it-should-be
+testsuccess apt install --with-source ./Packages pkg-as-it-should-be -s
+testsuccess apt install --with-source ./Packages pkg-as-it-should-be --print-uris
+testsuccess apt show --with-source ./Packages pkg-as-it-should-be
+testequal 'Package: pkg-as-it-should-be' head -n1 rootdir/tmp/testsuccess.output
+testsuccess apt install -y --with-source ./Packages pkg-as-it-should-be
+testdpkginstalled 'pkg-as-it-should-be'
index f7008084fbd1483333946c26b9654b08b3810ac7..b5ed3279faa4372094bc578ac4ca215520832407 100755 (executable)
@@ -32,7 +32,7 @@ testdpkginstalled 'aptkeyuser-depends'
 testfailure grep '^Warning: This will BREAK' apt.output
 testsuccess grep '^Warning: apt-key' apt.output
 
-testsuccess apt install ./incoming/aptkeyuser-nodepends_*.changes -y
+testsuccess apt install --with-source ./incoming/aptkeyuser-nodepends_*.changes aptkeyuser-nodepends -y
 cp rootdir/tmp/testsuccess.output apt.output
 testdpkginstalled 'aptkeyuser-nodepends'
 testsuccess grep '^Warning: This will BREAK' apt.output