Save previous dir and restore it before rmtree 20/13620/2
authorThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 22 Nov 2018 05:18:24 +0000 (13:18 +0800)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 22 Nov 2018 06:45:52 +0000 (14:45 +0800)
Make sure we restore the previous directory state before calling
rmtree.

Issue: RELENG-1512
Change-Id: Ie5ce6b3f4c19608c90a96c5cac63aa7c5ebd808d
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/deploy.py

index 0861d15..6f8128e 100644 (file)
@@ -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)