Bug #193695 - Add FreeBSD chflags support for rmdir()
authorZac Medico <zmedico@gentoo.org>
Tue, 25 Sep 2007 15:33:33 +0000 (15:33 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 25 Sep 2007 15:33:33 +0000 (15:33 -0000)
calls during unmerge.

svn path=/main/trunk/; revision=7807

pym/portage/dbapi/vartree.py

index ddf8c83283b81eb72ce16ddde4723ab3210fff95..fda5a2278820ee48009b5b1ddc0c3b40138910cf 100644 (file)
@@ -1331,7 +1331,22 @@ class dblink(object):
 
                        for obj in mydirs:
                                try:
-                                       os.rmdir(obj)
+                                       if bsd_chflags:
+                                               lstatobj = os.lstat(obj)
+                                               if lstatobj.st_flags != 0:
+                                                       bsd_chflags.lchflags(obj, 0)
+                                               parent_name = os.path.dirname(obj)
+                                               # Use normal stat/chflags for the parent since we want to
+                                               # follow any symlinks to the real parent directory.
+                                               pflags = os.stat(parent_name).st_flags
+                                               if pflags != 0:
+                                                       bsd_chflags.chflags(parent_name, 0)
+                                       try:
+                                               os.rmdir(obj)
+                                       finally:
+                                               if bsd_chflags and pflags != 0:
+                                                       # Restore the parent flags we saved before unlinking
+                                                       bsd_chflags.chflags(parent_name, pflags)
                                        show_unmerge("<<<", "", "dir", obj)
                                except EnvironmentError, e:
                                        if e.errno not in (errno.ENOENT,