egencache: prune empty cache directories v2.2.0_alpha114
authorZac Medico <zmedico@gentoo.org>
Wed, 27 Jun 2012 22:45:19 +0000 (15:45 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 27 Jun 2012 22:45:19 +0000 (15:45 -0700)
bin/egencache
pym/portage/cache/fs_template.py

index 2f53b40e327d40baf2d7a239e1f225d8e5791167..a75a34172cecdcd29ba166ddc1bbef7c987e117d 100755 (executable)
@@ -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):
index a82e8623acab8ebc1cdf6b235578c6a9b1c63282..8f0636ed013bd3b75f5c39c47b774b46f09f1ed2 100644 (file)
@@ -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: