From 1948e5fec0637f7c97c75f71e9dd11537fe59743 Mon Sep 17 00:00:00 2001
From: Balazs Lecz <leczb@google.com>
Date: Wed, 26 May 2010 16:52:27 +0100
Subject: [PATCH] Add RemoveDir utility function

Backported from master, 72087dcd5b06c0127e2ec3bf8c80f7f54da3fb01

Signed-off-by: Balazs Lecz <leczb@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/utils.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/utils.py b/lib/utils.py
index 1a8b185df..2ccc38707 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -381,6 +381,24 @@ def RemoveFile(filename):
       raise
 
 
+def RemoveDir(dirname):
+  """Remove an empty directory.
+
+  Remove a directory, ignoring non-existing ones.
+  Other errors are passed. This includes the case,
+  where the directory is not empty, so it can't be removed.
+
+  @type dirname: str
+  @param dirname: the empty directory to be removed
+
+  """
+  try:
+    os.rmdir(dirname)
+  except OSError, err:
+    if err.errno != errno.ENOENT:
+      raise
+
+
 def RenameFile(old, new, mkdir=False, mkdir_mode=0750):
   """Renames a file.
 
-- 
GitLab