[Notes] [Git][BuildStream/buildstream][jmac/tempfile-extraction-bug] 2 commits: tar tests: Add tarball which contains a read-only dir



Title: GitLab

Jim MacArthur pushed to branch jmac/tempfile-extraction-bug at BuildStream / buildstream

Commits:

4 changed files:

Changes:

  • tests/sources/tar.py
    ... ... @@ -3,6 +3,7 @@ import pytest
    3 3
     import tarfile
    
    4 4
     import tempfile
    
    5 5
     import subprocess
    
    6
    +from shutil import copyfile
    
    6 7
     
    
    7 8
     from buildstream._exceptions import ErrorDomain
    
    8 9
     from buildstream import _yaml
    
    ... ... @@ -257,3 +258,33 @@ def test_stage_default_basedir_lzip(cli, tmpdir, datafiles, srcdir):
    257 258
         original_contents = list_dir_contents(original_dir)
    
    258 259
         checkout_contents = list_dir_contents(checkoutdir)
    
    259 260
         assert(checkout_contents == original_contents)
    
    261
    +
    
    262
    +
    
    263
    +# Test that a tarball that contains a read only dir works
    
    264
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'read-only'))
    
    265
    +def test_read_only_dir(cli, tmpdir, datafiles):
    
    266
    +    try:
    
    267
    +        project = os.path.join(datafiles.dirname, datafiles.basename)
    
    268
    +        generate_project(project, tmpdir)
    
    269
    +
    
    270
    +        # Get the tarball in tests/sources/tar/read-only/content
    
    271
    +        #
    
    272
    +        # NOTE that we need to do this because tarfile.open and tar.add()
    
    273
    +        # are packing the tar up with writeable files and dirs
    
    274
    +        tarball = os.path.join(str(datafiles), 'content', 'a.tar.gz')
    
    275
    +        if not os.path.exists(tarball):
    
    276
    +            raise FileNotFoundError('{} does not exist'.format(tarball))
    
    277
    +        copyfile(tarball, os.path.join(tmpdir, 'a.tar.gz'))
    
    278
    +
    
    279
    +        # Track, fetch, build, checkout
    
    280
    +        result = cli.run(project=project, args=['track', 'target.bst'])
    
    281
    +        result.assert_success()
    
    282
    +        result = cli.run(project=project, args=['fetch', 'target.bst'])
    
    283
    +        result.assert_success()
    
    284
    +        result = cli.run(project=project, args=['build', 'target.bst'])
    
    285
    +        result.assert_success()
    
    286
    +    finally:
    
    287
    +        # Make tmpdir deletable no matter what happens
    
    288
    +        print("Cleaning {}".format(tmpdir))
    
    289
    +        for dirpath, dnames, fnames in os.walk(tmpdir):
    
    290
    +            os.chmod(dirpath, 0o777)

  • tests/sources/tar/read-only/content/a.tar.gz
    No preview for this file type
  • tests/sources/tar/read-only/target-lz.bst
    1
    +kind: import
    
    2
    +description: The kind of this element is irrelevant.
    
    3
    +sources:
    
    4
    +- kind: tar
    
    5
    +  url: tmpdir:/a.tar.lz
    
    6
    +  ref: foo

  • tests/sources/tar/read-only/target.bst
    1
    +kind: import
    
    2
    +description: The kind of this element is irrelevant.
    
    3
    +sources:
    
    4
    +- kind: tar
    
    5
    +  url: tmpdir:/a.tar.gz
    
    6
    +  ref: foo



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]