summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShahwat Dalal <sdalal29@bloomberg.net>2019-07-02 12:53:54 +0100
committerShahwat Dalal <sdalal29@bloomberg.net>2019-07-04 10:48:45 +0100
commit438ee733d67dbde09718fe45271628763b27b8e1 (patch)
treeacda735d6311dbf77e3b567801158bbf2c370dd4
parent1be4a7f1ea65af2f8ee6391a01a14dc685f5be26 (diff)
downloadbuildstream-shashwatdalal/tar-file-extraction.tar.gz
utils.py: Add write permission to root path in _force_rmtreeshashwatdalal/tar-file-extraction
This is needed in the case where the temp directory permissions are changed between creation and deletion.
-rw-r--r--src/buildstream/utils.py2
-rw-r--r--tests/sources/tar.py25
-rw-r--r--tests/sources/tar/read-only/content/b.tar.gzbin0 -> 148 bytes
3 files changed, 23 insertions, 4 deletions
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 775a11142..b5b554ee5 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -730,6 +730,8 @@ def _is_main_process():
# Recursively remove directories, ignoring file permissions as much as
# possible.
def _force_rmtree(rootpath, **kwargs):
+
+ os.chmod(rootpath, 0o755)
for root, dirs, _ in os.walk(rootpath):
for d in dirs:
path = os.path.join(root, d.lstrip('/'))
diff --git a/tests/sources/tar.py b/tests/sources/tar.py
index 07108ccbb..8d409b512 100644
--- a/tests/sources/tar.py
+++ b/tests/sources/tar.py
@@ -276,21 +276,38 @@ def test_stage_default_basedir_lzip(cli, tmpdir, datafiles, srcdir):
assert checkout_contents == original_contents
-# Test that a tarball that contains a read only dir works
+# Test that tarballs with read-only files work
+# a - contains read-only files in a writable directory
+# b - root directory has read-only permission
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'read-only'))
-def test_read_only_dir(cli, tmpdir, datafiles):
+@pytest.mark.parametrize("tar_name", ["a", "b"])
+def test_read_only_dir(cli, tmpdir, datafiles, tar_name):
try:
project = str(datafiles)
generate_project(project, tmpdir)
+ bst_path = os.path.join(project, "target.bst")
+ tar_file = "{}.tar.gz".format(tar_name)
+
+ _yaml.dump({
+ 'kind': 'import',
+ 'sources': [
+ {
+ 'kind': 'tar',
+ 'url': 'tmpdir:/{}'.format(tar_file),
+ 'ref': 'foo'
+ }
+ ]
+ }, bst_path)
+
# Get the tarball in tests/sources/tar/read-only/content
#
# NOTE that we need to do this because tarfile.open and tar.add()
# are packing the tar up with writeable files and dirs
- tarball = os.path.join(str(datafiles), 'content', 'a.tar.gz')
+ tarball = os.path.join(str(datafiles), 'content', tar_file)
if not os.path.exists(tarball):
raise FileNotFoundError('{} does not exist'.format(tarball))
- copyfile(tarball, os.path.join(str(tmpdir), 'a.tar.gz'))
+ copyfile(tarball, os.path.join(str(tmpdir), tar_file))
# Because this test can potentially leave directories behind
# which are difficult to remove, ask buildstream to use
diff --git a/tests/sources/tar/read-only/content/b.tar.gz b/tests/sources/tar/read-only/content/b.tar.gz
new file mode 100644
index 000000000..79fd1e864
--- /dev/null
+++ b/tests/sources/tar/read-only/content/b.tar.gz
Binary files differ