ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject ambari git commit: AMBARI-14462. Make Directory with create_parents=True, error messages more understanable (aonishuk)
Date Tue, 22 Dec 2015 11:12:30 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a4a530ab3 -> 2d8721a8b


AMBARI-14462. Make Directory with create_parents=True, error messages more understanable (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2d8721a8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2d8721a8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2d8721a8

Branch: refs/heads/trunk
Commit: 2d8721a8babb509b63d85eb26f266ec4c280b7ee
Parents: a4a530a
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Tue Dec 22 13:12:24 2015 +0200
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Dec 22 13:12:24 2015 +0200

----------------------------------------------------------------------
 .../main/python/resource_management/core/sudo.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2d8721a8/ambari-common/src/main/python/resource_management/core/sudo.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/sudo.py b/ambari-common/src/main/python/resource_management/core/sudo.py
index bb28d9f..5dbcddd 100644
--- a/ambari-common/src/main/python/resource_management/core/sudo.py
+++ b/ambari-common/src/main/python/resource_management/core/sudo.py
@@ -24,6 +24,7 @@ import os
 import tempfile
 import shutil
 import stat
+import errno
 from resource_management.core import shell
 from resource_management.core.logger import Logger
 from resource_management.core.exceptions import Fail
@@ -67,7 +68,23 @@ if os.geteuid() == 0:
     shutil.copy(src, dst)
     
   def makedirs(path, mode):
-    os.makedirs(path, mode)
+    try:
+      os.makedirs(path, mode)
+    except OSError as ex:
+      if ex.errno == errno.ENOENT:
+        dirname = os.path.dirname(ex.filename)
+        if os.path.islink(dirname) and not os.path.exists(dirname):
+          raise Fail("Cannot create directory '{0}' as '{1}' is a broken symlink".format(path,
dirname))
+      elif ex.errno == errno.ENOTDIR:
+        dirname = os.path.dirname(ex.filename)
+        if os.path.isfile(dirname):
+          raise Fail("Cannot create directory '{0}' as '{1}' is a file".format(path, dirname))
+      elif ex.errno == errno.ELOOP:
+        dirname = os.path.dirname(ex.filename)
+        if os.path.islink(dirname) and not os.path.exists(dirname):
+          raise Fail("Cannot create directory '{0}' as '{1}' is a looped symlink".format(path,
dirname))
+        
+      raise
   
   def makedir(path, mode):
     os.mkdir(path)


Mime
View raw message