]> git.saurik.com Git - apt.git/commitdiff
Add new APT::Keep-Downloaded-Packages option
authorMichael Vogt <mvo@ubuntu.com>
Sat, 2 Jan 2016 21:08:30 +0000 (22:08 +0100)
committerMichael Vogt <mvo@ubuntu.com>
Sat, 2 Jan 2016 21:18:13 +0000 (22:18 +0100)
This option controls if downloaded packages should be kept after
a successful install or if they should be deleted. The default
for "apt-get" is that they are kept (just like before).

However the default for "apt" is that they get deleted.

Closes: #160743
apt-private/private-cmndline.cc
apt-private/private-install.cc
test/integration/test-apt-keep-downloaded-pkgs [new file with mode: 0755]

index 6cffbcb488eadb8cf610e935a96204f2c7fb6066..9234aa27805042bf01ff43b3eb84c1bee9915a13 100644 (file)
@@ -435,6 +435,7 @@ static void BinarySpecificConfiguration(char const * const Binary)  /*{{{*/
       _config->CndSet("Binary::apt::APT::Cmd::Show-Update-Stats", true);
       _config->CndSet("Binary::apt::DPkg::Progress-Fancy", true);
       _config->CndSet("Binary::apt::Acquire::AllowInsecureRepositories", false);
+      _config->CndSet("Binary::apt::APT::Keep-Downloaded-Packages", false);
    }
 
    _config->Set("Binary", binary);
index 74a2424c56d2ef19d0fc284a5b3607b7e48507ef..73aebaf2f5dc7a140f69ffa51d5622c5578bee34 100644 (file)
@@ -346,6 +346,18 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
    }
 
+   // cleanup downloaded debs
+   if (_config->FindB("APT::Keep-Downloaded-Packages", true) == false)
+   {
+      std::string const archivedir = _config->FindDir("Dir::Cache::archives");
+      for (auto I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
+      {
+        if (flNotFile((*I)->DestFile) != archivedir || (*I)->Local)
+           continue;
+         RemoveFile("Keep-Downloaded-Packages=false", (*I)->DestFile);
+      }
+   }
+
    return true;
 }
                                                                        /*}}}*/
diff --git a/test/integration/test-apt-keep-downloaded-pkgs b/test/integration/test-apt-keep-downloaded-pkgs
new file mode 100755 (executable)
index 0000000..4cc7fbb
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+set -e
+
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
+
+setupenvironment
+configarchitecture 'native'
+
+buildsimplenativepackage 'pkg1' 'all' '1.0' 'stable'
+buildsimplenativepackage 'pkg2' 'all' '1.0' 'stable'
+buildsimplenativepackage 'pkg3' 'all' '1.0' 'stable'
+buildsimplenativepackage 'pkg4' 'all' '1.0' 'stable'
+
+# local (file) installs
+setupaptarchive
+
+# ensure that install from local sources does not remove debs
+testsuccess aptget install pkg1 -o APT::Keep-Downloaded-Packages=false
+testsuccess test -f aptarchive/pool/pkg1_1.0_all.deb
+
+# now switch to http and downloading debs
+changetowebserver
+testsuccess aptget update
+
+# ensure that the downloaded pkg is kept with "keep=true"
+testsuccess aptget install pkg2 -o APT::Keep-Downloaded-Packages=true
+testsuccess test -f aptarchive/pool/pkg2_1.0_all.deb
+testsuccess test -f rootdir/var/cache/apt/archives/pkg2_1.0_all.deb
+
+# ensure that the downloaded pkg is removed when requested
+testsuccess aptget install pkg3 -o APT::Keep-Downloaded-Packages=false
+testsuccess test -f aptarchive/pool/pkg3_1.0_all.deb
+# this was there before, keep it
+testsuccess test -f rootdir/var/cache/apt/archives/pkg2_1.0_all.deb
+# this got installed so we can remove it now
+testfailure test -f rootdir/var/cache/apt/archives/pkg3_1.0_all.deb
+
+
+# ensure that install from the download dir does not delete packages
+mv aptarchive/pool/pkg4_1.0_all.deb rootdir/var/cache/apt/archives
+testsuccess aptget install $(pwd)/rootdir/var/cache/apt/archives/pkg4_1.0_all.deb -o APT::Keep-Downloaded-Packages=false
+testsuccess test -f $(pwd)/rootdir/var/cache/apt/archives/pkg4_1.0_all.deb
\ No newline at end of file