From 04b80279162a76d8347a2d168f52b9b987b31a04 Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Thu, 26 Apr 2007 15:58:03 -0700
Subject: [PATCH] pyutil: fileutil: make temp dir cleanup more robust against
 failure during initializationor other internal inconsistency

---
 src/zfec/zfec/util/fileutil.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/zfec/zfec/util/fileutil.py b/src/zfec/zfec/util/fileutil.py
index 98c5d914..2821c973 100644
--- a/src/zfec/zfec/util/fileutil.py
+++ b/src/zfec/zfec/util/fileutil.py
@@ -117,12 +117,13 @@ class _Dir(object):
         self.subdirs.add(dirobj)
        
     def shutdown(self):
-        if self.cleanup and hasattr(self, 'name'):
-            for subdir in self.subdirs:
+        if self.cleanup:
+            for subdir in hasattr(self, 'subdirs') and self.subdirs or []:
                 subdir.shutdown()
-            for fileobj in self.files:
+            for fileobj in hasattr(self, 'files') and self.files or []:
                 fileobj.close() # "close()" is idempotent so we don't need to catch exceptions here
-            rm_dir(self.name)
+            if hasattr(self, 'name'):
+                rm_dir(self.name)
 
     def __repr__(self):
         return "<%s instance at %x %s>" % (self.__class__.__name__, id(self), self.name)
-- 
2.45.2