From 71eca7c3955e096fc85f8e75a959358d56f0ab5a Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 12 Oct 2007 12:30:42 +0000 Subject: [PATCH] Do not walk the whole DATA_DIR on node leave Since we remove only files from DATA_DIR and not from subdirectories, let's not walk the entire tree, a simple listdir suffices. Also switch to utils.RemoveFile from simple os.unlink. Reviewed-by: imsnah --- lib/backend.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 295697db4..c8d1dd095 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -129,11 +129,11 @@ def LeaveCluster(): """Cleans up the current node and prepares it to be removed from the cluster. """ - if os.path.exists(constants.DATA_DIR): - for dirpath, dirnames, filenames in os.walk(constants.DATA_DIR): - if dirpath == constants.DATA_DIR: - for i in filenames: - os.unlink(os.path.join(dirpath, i)) + if os.path.isdir(constants.DATA_DIR): + for rel_name in utils.ListVisibleFiles(constants.DATA_DIR): + full_name = os.path.join(constants.DATA_DIR, rel_name) + if os.path.isfile(full_name) and not os.path.islink(full_name): + utils.RemoveFile(full_name) f = open('/root/.ssh/id_dsa.pub', 'r') try: -- GitLab