Make ensure_dirs() behave correctly for DragonFly when EPERM is raised for
authorZac Medico <zmedico@gentoo.org>
Wed, 7 Apr 2010 03:54:11 +0000 (20:54 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 7 Apr 2010 03:54:11 +0000 (20:54 -0700)
makedir('/'). Thanks to Naohiro Aota <naota@elisp.net> for the initial patch.

pym/portage/util/__init__.py

index 541204334fc79afffaeb65c6d99262f452262cc6..ac191fb2a2d7c87ecabb6735454c08087b0ebc13 100644 (file)
@@ -1046,14 +1046,19 @@ def ensure_dirs(dir_path, *args, **kwargs):
                func_call = "makedirs('%s')" % dir_path
                if oe.errno in (errno.EEXIST, errno.EISDIR):
                        pass
-               elif oe.errno == errno.EPERM:
-                       raise OperationNotPermitted(func_call)
-               elif oe.errno == errno.EACCES:
-                       raise PermissionDenied(func_call)
-               elif oe.errno == errno.EROFS:
-                       raise ReadOnlyFileSystem(func_call)
                else:
-                       raise
+                       if os.path.isdir(dir_path):
+                               # NOTE: DragonFly raises EPERM for makedir('/')
+                               # and that is supposed to be ignored here.
+                               pass
+                       elif oe.errno == errno.EPERM:
+                               raise OperationNotPermitted(func_call)
+                       elif oe.errno == errno.EACCES:
+                               raise PermissionDenied(func_call)
+                       elif oe.errno == errno.EROFS:
+                               raise ReadOnlyFileSystem(func_call)
+                       else:
+                               raise
        perms_modified = apply_permissions(dir_path, *args, **kwargs)
        return created_dir or perms_modified