From 9b264c4f8c08aaa2f7b87c825c73f121d1156cdb Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Thu, 22 Nov 2018 13:18:24 +0800 Subject: [PATCH] Save previous dir and restore it before rmtree Make sure we restore the previous directory state before calling rmtree. Issue: RELENG-1512 Change-Id: Ie5ce6b3f4c19608c90a96c5cac63aa7c5ebd808d Signed-off-by: Thanh Ha --- lftools/deploy.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lftools/deploy.py b/lftools/deploy.py index 0861d155..6f8128e8 100644 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -215,6 +215,7 @@ def deploy_archives(nexus_url, nexus_path, workspace, pattern=None): archive. (optional) """ nexus_url = _format_url(nexus_url) + previous_dir = os.getcwd() work_dir = tempfile.mkdtemp(prefix='lftools-da.') os.chdir(work_dir) log.debug('workspace: {}, work_dir: {}'.format(workspace, work_dir)) @@ -226,6 +227,8 @@ def deploy_archives(nexus_url, nexus_path, workspace, pattern=None): '{}/archives'.format(workspace), 'zip') log.debug('archives zip: {}'.format(archives_zip)) deploy_nexus_zip(nexus_url, 'logs', nexus_path, archives_zip) + + os.chdir(previous_dir) shutil.rmtree(work_dir) @@ -248,6 +251,7 @@ def deploy_logs(nexus_url, nexus_path, build_url): via the $BUILD_URL environment variable. """ nexus_url = _format_url(nexus_url) + previous_dir = os.getcwd() work_dir = tempfile.mkdtemp(prefix='lftools-dl.') os.chdir(work_dir) log.debug('work_dir: {}'.format(work_dir)) @@ -303,6 +307,8 @@ def deploy_logs(nexus_url, nexus_path, build_url): shutil.make_archive(console_zip.name, 'zip', work_dir) deploy_nexus_zip(nexus_url, 'logs', nexus_path, '{}.zip'.format(console_zip.name)) console_zip.close() + + os.chdir(previous_dir) shutil.rmtree(work_dir) -- 2.16.6