Bug#508215: apt-get free-upgrade to ugrade only the packages that leave free space from the disk
Package: apt
Version: 0.7.11
Severity: wishlist
Tags: patch
I think that its very interesting to have one opcion like apt-get free-upgrade to be able to ugrade only the packages that leave free space from the disk.
I could improve this patch with some help.
-- Package-specific info:
-- (/etc/apt/preferences present, but not submitted) --
-- (/etc/apt/sources.list present, but not submitted) --
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)
Kernel: Linux 2.6.24-1-686 (SMP w/4 CPU cores)
Locale: LANG=es_ES.UTF-8, LC_CTYPE=es_ES.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages apt depends on:
ii debian-archive-keyring 2007.07.31~etch1 GnuPG archive keys of the Debian a
ii libc6 2.7-16 GNU C Library: Shared libraries
ii libgcc1 1:4.3.2-1 GCC support library
ii libstdc++6 4.3.2-1 The GNU Standard C++ Library v3
apt recommends no packages.
Versions of packages apt suggests:
pn apt-doc <none> (no description available)
ii aptitude 0.4.10-1+b2 terminal-based package manager
ii bzip2 1.0.5-1 high-quality block-sorting file co
ii dpkg-dev 1.14.16.6 package building tools for Debian
ii lzma 4.43-12 Compression method of 7z format in
-- no debconf information
*** /home/orens/perl/apt/patch.diff
diff -urN apt-0.7.19/apt-pkg/algorithms.cc apt-0.7.19-patch/apt-pkg/algorithms.cc
--- apt-0.7.19/apt-pkg/algorithms.cc 2008-11-24 09:32:23.000000000 +0000
+++ apt-0.7.19-patch/apt-pkg/algorithms.cc 2008-12-08 19:06:09.000000000 +0000
@@ -1385,4 +1385,44 @@
RunScripts("APT::Update::Post-Invoke");
return true;
}
+ /*}}}*
+
+// FreeUpgrade - upgrade only packages which free user space /*{{{*/
+// ---------------------------------------------------------------------
+/*
+ */
+bool pkgFreeUpgrade(pkgDepCache &Cache)
+{
+ int oldsize=0;
+ int newsize=0;
+ pkgDepCache::ActionGroup group(Cache);
+
+ pkgProblemResolver Fix(&Cache);
+
+ if (Cache.BrokenCount() != 0)
+ return false;
+
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ {
+ if (Cache[I].Install() == true)
+ Fix.Protect(I);
+
+ if (_config->FindB("APT::Ignore-Hold",false) == false)
+ if (I->SelectedState == pkgCache::State::Hold)
+ continue;
+
+ if (I->CurrentVer != 0 && Cache[I].InstallVer != 0)
+ {
+ Cache.MarkInstall(I, false, 0, false);
+ newsize=Cache.UsrSize();
+ if(newsize>oldsize)
+ {
+ Cache.MarkKeep(I, false, false);
+ }
+ oldsize=newsize;
+
+ }
+ }
+ return Fix.ResolveByKeep();
+}
/*}}}*/
diff -urN apt-0.7.19/apt-pkg/algorithms.h apt-0.7.19-patch/apt-pkg/algorithms.h
--- apt-0.7.19/apt-pkg/algorithms.h 2008-10-01 16:33:56.000000000 +0000
+++ apt-0.7.19-patch/apt-pkg/algorithms.h 2008-12-08 19:06:09.000000000 +0000
@@ -134,5 +134,7 @@
void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
-
+
+bool pkgFreeUpgrade(pkgDepCache &Cache);
+
#endif
diff -urN apt-0.7.19/cmdline/apt-get.cc apt-0.7.19-patch/cmdline/apt-get.cc
--- apt-0.7.19/cmdline/apt-get.cc 2008-11-24 09:32:23.000000000 +0000
+++ apt-0.7.19-patch/cmdline/apt-get.cc 2008-12-08 19:05:53.000000000 +0000
@@ -2565,6 +2565,26 @@
return true;
}
/*}}}*/
+
+// DoFreeUpgrade - Automatic smart upgrader but only packages which free user space /*{{{*/
+// ---------------------------------------------------------------------
+/* Intelligent upgrader that will install packages which free user space */
+bool DoFreeUpgrade(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
+ return false;
+
+ c0out << _("Calculating upgrade... ") << flush;
+ if (pkgFreeUpgrade(*Cache) == false)
+ {
+ c0out << _("Failed") << endl;
+ ShowBroken(c1out,Cache,false);
+ return false;
+ }
+ return InstallPackages(Cache,true);
+}
+ /*}}}*/
// ShowHelp - Show a help screen /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -2751,6 +2771,7 @@
{"check",&DoCheck},
{"source",&DoSource},
{"moo",&DoMoo},
+ {"free-upgrade",&DoFreeUpgrade},
{"help",&ShowHelp},
{0,0}};
diff -urN apt-0.7.19/apt-pkg/algorithms.cc apt-0.7.19-patch/apt-pkg/algorithms.cc
--- apt-0.7.19/apt-pkg/algorithms.cc 2008-11-24 09:32:23.000000000 +0000
+++ apt-0.7.19-patch/apt-pkg/algorithms.cc 2008-12-08 19:06:09.000000000 +0000
@@ -1385,4 +1385,44 @@
RunScripts("APT::Update::Post-Invoke");
return true;
}
+ /*}}}*
+
+// FreeUpgrade - upgrade only packages which free user space /*{{{*/
+// ---------------------------------------------------------------------
+/*
+ */
+bool pkgFreeUpgrade(pkgDepCache &Cache)
+{
+ int oldsize=0;
+ int newsize=0;
+ pkgDepCache::ActionGroup group(Cache);
+
+ pkgProblemResolver Fix(&Cache);
+
+ if (Cache.BrokenCount() != 0)
+ return false;
+
+ for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
+ {
+ if (Cache[I].Install() == true)
+ Fix.Protect(I);
+
+ if (_config->FindB("APT::Ignore-Hold",false) == false)
+ if (I->SelectedState == pkgCache::State::Hold)
+ continue;
+
+ if (I->CurrentVer != 0 && Cache[I].InstallVer != 0)
+ {
+ Cache.MarkInstall(I, false, 0, false);
+ newsize=Cache.UsrSize();
+ if(newsize>oldsize)
+ {
+ Cache.MarkKeep(I, false, false);
+ }
+ oldsize=newsize;
+
+ }
+ }
+ return Fix.ResolveByKeep();
+}
/*}}}*/
diff -urN apt-0.7.19/apt-pkg/algorithms.h apt-0.7.19-patch/apt-pkg/algorithms.h
--- apt-0.7.19/apt-pkg/algorithms.h 2008-10-01 16:33:56.000000000 +0000
+++ apt-0.7.19-patch/apt-pkg/algorithms.h 2008-12-08 19:06:09.000000000 +0000
@@ -134,5 +134,7 @@
void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
-
+
+bool pkgFreeUpgrade(pkgDepCache &Cache);
+
#endif
diff -urN apt-0.7.19/cmdline/apt-get.cc apt-0.7.19-patch/cmdline/apt-get.cc
--- apt-0.7.19/cmdline/apt-get.cc 2008-11-24 09:32:23.000000000 +0000
+++ apt-0.7.19-patch/cmdline/apt-get.cc 2008-12-08 19:05:53.000000000 +0000
@@ -2565,6 +2565,26 @@
return true;
}
/*}}}*/
+
+// DoFreeUpgrade - Automatic smart upgrader but only packages which free user space /*{{{*/
+// ---------------------------------------------------------------------
+/* Intelligent upgrader that will install packages which free user space */
+bool DoFreeUpgrade(CommandLine &CmdL)
+{
+ CacheFile Cache;
+ if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
+ return false;
+
+ c0out << _("Calculating upgrade... ") << flush;
+ if (pkgFreeUpgrade(*Cache) == false)
+ {
+ c0out << _("Failed") << endl;
+ ShowBroken(c1out,Cache,false);
+ return false;
+ }
+ return InstallPackages(Cache,true);
+}
+ /*}}}*/
// ShowHelp - Show a help screen /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -2751,6 +2771,7 @@
{"check",&DoCheck},
{"source",&DoSource},
{"moo",&DoMoo},
+ {"free-upgrade",&DoFreeUpgrade},
{"help",&ShowHelp},
{0,0}};
Reply to: