From 54932ac1af5761fd055e90b358d380e828a95d54 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 27 Jun 2012 15:45:19 -0700 Subject: [PATCH] egencache: prune empty cache directories --- bin/egencache | 3 +++ pym/portage/cache/fs_template.py | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bin/egencache b/bin/egencache index 2f53b40e3..a75a34172 100755 --- a/bin/egencache +++ b/bin/egencache @@ -426,6 +426,9 @@ class GenCache(object): "committing target: %s\n" % (ce,), level=logging.ERROR, noiselevel=-1) + if hasattr(trg_cache, '_prune_empty_dirs'): + trg_cache._prune_empty_dirs() + class GenUseLocalDesc(object): def __init__(self, portdb, output=None, preserve_comments=False): diff --git a/pym/portage/cache/fs_template.py b/pym/portage/cache/fs_template.py index a82e8623a..8f0636ed0 100644 --- a/pym/portage/cache/fs_template.py +++ b/pym/portage/cache/fs_template.py @@ -1,14 +1,14 @@ -# Copyright: 2005 Gentoo Foundation +# Copyright 2005-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 # Author(s): Brian Harring (ferringb@gentoo.org) -# License: GPL2 +import os as _os import sys from portage.cache import template from portage import os from portage.proxy.lazyimport import lazyimport lazyimport(globals(), - 'portage.data:portage_gid', 'portage.exception:PortageException', 'portage.util:apply_permissions', ) @@ -22,10 +22,6 @@ class FsBased(template.database): attempt to ensure files have the specified owners/perms""" def __init__(self, *args, **config): - """throws InitializationError if needs args aren't specified - gid and perms aren't listed do to an oddity python currying mechanism - gid=portage_gid - perms=0665""" for x, y in (("gid", -1), ("perms", -1)): if x in config: @@ -78,7 +74,17 @@ class FsBased(template.database): if self._perms != -1: os.umask(um) - + def _prune_empty_dirs(self): + all_dirs = [] + for parent, dirs, files in os.walk(self.location): + for x in dirs: + all_dirs.append(_os.path.join(parent, x)) + while all_dirs: + try: + _os.rmdir(all_dirs.pop()) + except OSError: + pass + def gen_label(base, label): """if supplied label is a path, generate a unique label based upon label, and supplied base path""" if label.find(os.path.sep) == -1: -- 2.26.2