This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Knowledge Base:Remove obsoleted distfiles

From Gentoo Wiki (test)
Jump to:navigation Jump to:search

Synopsis

The DISTDIR location hosts all the source code archives downloaded by the system. Unless the files are properly removed when no longer needed, the storage occupied by this location will continue to grow. Regular clean-up of this location is not performed automatically by Portage.

Environment

Any Gentoo Linux installation.

Analysis

When Portage needs to download source code archives, it will store these archives in DISTDIR for later use. Portage will never clean up this location by itself; it will wait for a user with root privileges to do so.

Cleaning up the DISTDIR location means that the user should check which source code archives to keep and which to delete.

  • If the system is tight on space and there are no problems in re-downloading the source code archives when necessary, then the entire DISTDIR can be cleaned
  • If the system is tight on space, and the user would rather not re-download source code of packages that are currently installed (in case a rebuild the software is needed the sources will present on the system), then only clean out source code archives that are no longer used by any installed software

Of course, other clean-up strategies might exist as well. The above examples are provided as hypothetical situations.

Resolution

The app-portage/gentoolkit package provides an utility called eclean-dist which supports, among other strategies, the following clean-up activities.

Running eclean-dist will remove the source code archives that do not belong to any available ebuild anymore. This is a safe approach since these sources are very unlikely to be needed again (most of these archives are of old ebuilds that have since been removed from the Gentoo ebuild repository).

root #eclean-dist

The --deep option can be added to make eclean-dist remove the source code archives that do not belong to an installed ebuild. This will remove many more sources, but is still not be that troublesome since the source code archives of installed ebuilds remain available in case a rebuild is needed.

root #eclean-dist --deep

A more drastic approach to save disk space

An other option is to clean the distfiles after every successful merged ebuild, for that you may set the following hook (or install darkelf-features from darkelf overlay):

FILE /etc/portage/bashrcImplementing function to clean distfiles for every merge
# darkelf-features-0.1::darkelf
#
# This enables cleaning the distfiles after every emerge,
# to enable this feature set
# DARKELF_FEATURES="postmerge_distclean"
# in /etc/portage/make.conf or per command basis e.g.:
# DARKELF_FEATURES="postmerge_distclean" emerge ...

darkelf_postmerge_distclean(){
 echo cleaning distfiles for ${CATEGORY}/${PF}...
 if [ -z $DISTDIR ] ; then
  echo ERROR: DISTDIR is empty!
  exit 1
 fi
 for f in $DISTDIR/* ; do
  echo deleting "`readlink -f $f`"...
  rm -r "`readlink -f $f`"
 done
}

post_pkg_postinst(){
 if grep -q "postmerge_distclean" <<< $DARKELF_FEATURES ; then
  darkelf_postmerge_distclean
 fi
}

This clean feature can then be enabled by adding the following line to make.conf:

FILE /etc/portage/make.confEnabling function to clean distfiles for every merge
DARKELF_FEATURES="postmerge_distclean"

A few useful options

There are several useful options, so be sure to look at them. The --help option outputs lots of useful information. For example, --pretend functions as it does with emerge, showing what will happen without actually doing anything. Another nice option that can be used in conjunction with --deep is --fetch-restricted. Downloading Java from Oracle is annoying enough the first time; this will keep users from reliving the painful experience of re-downloading source code for their systems... at least until the next release.

See also