From: Thanh Ha Date: Thu, 22 Nov 2018 05:18:24 +0000 (+0800) Subject: Save previous dir and restore it before rmtree X-Git-Tag: v0.19.0~6 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F13620%2F2;p=releng%2Flftools.git 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 --- 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)