From 438ee733d67dbde09718fe45271628763b27b8e1 Mon Sep 17 00:00:00 2001 From: Shahwat Dalal Date: Tue, 2 Jul 2019 12:53:54 +0100 Subject: utils.py: Add write permission to root path in _force_rmtree This is needed in the case where the temp directory permissions are changed between creation and deletion. --- src/buildstream/utils.py | 2 ++ tests/sources/tar.py | 25 +++++++++++++++++++++---- tests/sources/tar/read-only/content/b.tar.gz | Bin 0 -> 148 bytes 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/sources/tar/read-only/content/b.tar.gz 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 Binary files /dev/null and b/tests/sources/tar/read-only/content/b.tar.gz differ -- cgit v1.2.1