Skip to content

Commit

Permalink
Remove the archive file from the system after unpack
Browse files Browse the repository at this point in the history
Summary:
The bundledDepends and assetDepends archive files were not deleted from the
worker after unpacking.

Updated 'dx-unpack' to remove the files after unpacking.

Alternatively dxpy.utils.exec_utils._install_dep_bundle() could be
updated to remove the file after unpacking.

Test Plan: dx-toolkit-home/src/python/test/test_dxunpack.py TestDXUnpack.test_remove_file_after_unpack

Reviewers: psung

Reviewed By: psung

Differential Revision: https://dnanexus.phacility.com/D1103
  • Loading branch information
Abhiram Das committed Aug 26, 2016
1 parent 6bb6c34 commit a84e18b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
1 change: 1 addition & 0 deletions bin/dx-unpack
Expand Up @@ -60,4 +60,5 @@ if [[ $output != "" ]]; then
rmdir "$tempdir"
else
unpack "$@"
rm -f "$@"
fi
13 changes: 0 additions & 13 deletions src/python/test/test_dxclient.py
Expand Up @@ -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"
Expand Down
62 changes: 62 additions & 0 deletions 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()

0 comments on commit a84e18b

Please sign in to comment.