diff --git a/bin/dx-unpack b/bin/dx-unpack index 9a3f986819..676fc7ad89 100755 --- a/bin/dx-unpack +++ b/bin/dx-unpack @@ -60,4 +60,5 @@ if [[ $output != "" ]]; then rmdir "$tempdir" else unpack "$@" + rm -f "$@" fi diff --git a/src/python/test/test_dxclient.py b/src/python/test/test_dxclient.py index 4a023d5ce3..8fe3e42dd4 100755 --- a/src/python/test/test_dxclient.py +++ b/src/python/test/test_dxclient.py @@ -2918,19 +2918,6 @@ def test_bundledDepends_name_with_whitespaces(self): applet_job.wait_on_done() self.assertEqual(applet_job.describe()['state'], 'done') - def test_bundledDepends_name_with_special_chars_locally(self): - # dx-unpack will fail for tarball names containing '$' at the begining of a word, - # example: "test '$bundle' \"with\" \"@#^&%()[]{}\" spaces.tar.gz" - bundle_name = "test 'bundle' \"with\" \"@#^&%()[]{}\" spaces.tar.gz" - bundle_tmp_dir = tempfile.mkdtemp() - os.mkdir(os.path.join(bundle_tmp_dir, "a")) - with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle: - file_in_bundle.write('foo\n') - subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name), - '-C', os.path.join(bundle_tmp_dir, 'a'), '.']) - subprocess.check_call(["dx-unpack", os.path.join(bundle_tmp_dir, bundle_name)]) - os.remove(os.path.join(os.getcwd(), 'foo.txt')) - class TestDXClientWorkflow(DXTestCase): default_inst_type = "mem2_hdd2_x2" diff --git a/src/python/test/test_dxunpack.py b/src/python/test/test_dxunpack.py new file mode 100755 index 0000000000..a4107b1e5b --- /dev/null +++ b/src/python/test/test_dxunpack.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2016 DNAnexus, Inc. +# +# This file is part of dx-toolkit (DNAnexus platform client libraries). +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from __future__ import print_function, unicode_literals, division, absolute_import + +import os +import unittest +import tempfile +import shutil +import subprocess +from dxpy_testutil import (DXTestCase) + + +class TestDXUnpack(DXTestCase): + def test_file_name_with_special_chars_locally(self): + # create a tar.gz file with spaces, quotes and escape chars in its name + bundle_name = "test 'bundle' \"with\" \"@#^&%()[]{}\" spaces.tar.gz" + bundle_tmp_dir = tempfile.mkdtemp() + os.mkdir(os.path.join(bundle_tmp_dir, "a")) + with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle: + file_in_bundle.write('foo\n') + subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name), + '-C', os.path.join(bundle_tmp_dir, 'a'), '.']) + extract_tmp_dir = tempfile.mkdtemp() + os.chdir(extract_tmp_dir) + subprocess.check_call(["dx-unpack", os.path.join(bundle_tmp_dir, bundle_name)]) + self.assertTrue(os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt'))) + + def test_remove_file_after_unpack(self): + # dx-unpack removes the file after unpacking + bundle_name = "tarball.tar.gz" + bundle_tmp_dir = tempfile.mkdtemp() + os.mkdir(os.path.join(bundle_tmp_dir, "a")) + with open(os.path.join(bundle_tmp_dir, 'a', 'foo.txt'), 'w') as file_in_bundle: + file_in_bundle.write('foo\n') + subprocess.check_call(['tar', '-czf', os.path.join(bundle_tmp_dir, bundle_name), + '-C', os.path.join(bundle_tmp_dir, 'a'), '.']) + extract_tmp_dir = tempfile.mkdtemp() + os.chdir(extract_tmp_dir) + subprocess.check_call(["dx-unpack", os.path.join(bundle_tmp_dir, bundle_name)]) + self.assertTrue(os.path.exists(os.path.join(extract_tmp_dir, 'foo.txt'))) + shutil.rmtree(os.path.join(bundle_tmp_dir, "a")) + self.assertFalse(os.path.exists(os.path.join(bundle_tmp_dir, bundle_name))) + +if __name__ == '__main__': + unittest.main()