ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [04/12] ambari git commit: AMBARI-18527 HostCleanup.py to be able to resolve wildcards in a dir or file path to a list of dirs and files (dili)
Date Thu, 06 Oct 2016 16:00:38 GMT
AMBARI-18527 HostCleanup.py to be able to resolve wildcards in a dir or file path to a list
of dirs and files (dili)


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

Branch: refs/heads/branch-feature-AMBARI-18456
Commit: 713f413c35c15d08f91bea619ecd7e9d1e877b9b
Parents: 1f7edfb
Author: Di Li <dili@apache.org>
Authored: Wed Oct 5 16:19:10 2016 -0400
Committer: Di Li <dili@apache.org>
Committed: Wed Oct 5 16:19:10 2016 -0400

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/HostCleanup.py | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/713f413c/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
index a3c72e6..cca79a8 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
@@ -35,6 +35,7 @@ import optparse
 import shlex
 import datetime
 import tempfile
+import glob
 from AmbariConfig import AmbariConfig
 from ambari_agent.Constants import AGENT_TMP_DIR
 from ambari_commons import OSCheck, OSConst
@@ -388,18 +389,25 @@ class HostCleanup:
 
   def do_erase_dir_silent(self, pathList):
     if pathList:
-      for path in pathList:
-        if path and os.path.exists(path):
-          if os.path.isdir(path):
-            try:
-              shutil.rmtree(path)
-            except:
-              logger.warn("Failed to remove dir: " + path + ", error: " + str(sys.exc_info()[0]))
-          else:
-            logger.info(path + " is a file and not a directory, deleting file")
-            self.do_erase_files_silent([path])
-        else:
-          logger.info("Path doesn't exists: " + path)
+      for aPath in pathList:
+        pathArr = glob.glob(aPath)
+        logger.debug("Resolved {0} to {1}".format(aPath, ','.join(pathArr)))
+        for path in pathArr:
+          if path:
+            if os.path.exists(path):
+              if os.path.isdir(path):
+                try:
+                  shutil.rmtree(path)
+                except:
+                  logger.warn("Failed to remove dir {0} , error: {1}".format(path, str(sys.exc_info()[0])))
+              else:
+                logger.info("{0} is a file, deleting file".format(path))
+                self.do_erase_files_silent([path])
+            elif os.path.islink(path):
+              logger.info("Deleting broken symbolic link {0}".format(path))
+              self.do_erase_files_silent([path])
+            else:
+              logger.info("Path doesn't exists: {0}".format(path))
     return 0
 
   def do_erase_files_silent(self, pathList):


Mime
View raw message