[Notes] [Git][BuildStream/buildstream][edbaunton/executable-remote-source] remote.py: expressly chmod downloaded file



Title: GitLab

Ed Baunton pushed to branch edbaunton/executable-remote-source at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/plugins/sources/remote.py
    ... ... @@ -55,7 +55,6 @@ remote - stage files from remote urls
    55 55
     
    
    56 56
     """
    
    57 57
     import os
    
    58
    -import stat
    
    59 58
     from buildstream import SourceError, utils
    
    60 59
     from ._downloadablefilesource import DownloadableFileSource
    
    61 60
     
    
    ... ... @@ -85,9 +84,12 @@ class RemoteSource(DownloadableFileSource):
    85 84
     
    
    86 85
                 utils.safe_copy(self._get_mirror_file(), dest)
    
    87 86
     
    
    87
    +            # To prevent user's umask introducing variability here, explicitly set
    
    88
    +            # file modes.
    
    88 89
                 if self.executable:
    
    89
    -                st = os.stat(dest)
    
    90
    -                os.chmod(dest, st.st_mode | stat.S_IEXEC)
    
    90
    +                os.chmod(dest, 0o755)
    
    91
    +            else:
    
    92
    +                os.chmod(dest, 0o644)
    
    91 93
     
    
    92 94
     
    
    93 95
     def setup():
    

  • tests/sources/remote.py
    ... ... @@ -86,7 +86,11 @@ def test_simple_file_build(cli, tmpdir, datafiles):
    86 86
         checkout_file = os.path.join(checkoutdir, 'file')
    
    87 87
         assert(os.path.exists(checkout_file))
    
    88 88
     
    
    89
    -    assert(not (os.stat(checkout_file).st_mode & stat.S_IEXEC))
    
    89
    +    mode = os.stat(checkout_file).st_mode
    
    90
    +    # Assert not executable by anyone
    
    91
    +    assert(not (mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)))
    
    92
    +    # Assert not writeable by anyone other than me
    
    93
    +    assert(not (mode & (stat.S_IWGRP | stat.S_IWOTH)))
    
    90 94
     
    
    91 95
     
    
    92 96
     @pytest.mark.datafiles(os.path.join(DATA_DIR, 'single-file-custom-name'))
    
    ... ... @@ -156,6 +160,7 @@ def test_executable(cli, tmpdir, datafiles):
    156 160
         result = cli.run(project=project, args=[
    
    157 161
             'checkout', 'target-custom-executable.bst', checkoutdir
    
    158 162
         ])
    
    159
    -
    
    160
    -    assert (os.stat(
    
    161
    -        os.path.join(checkoutdir, 'some-custom-file')).st_mode & stat.S_IEXEC)
    163
    +    mode = os.stat(os.path.join(checkoutdir, 'some-custom-file')).st_mode
    
    164
    +    assert (mode & stat.S_IEXEC)
    
    165
    +    # Assert executable by anyone
    
    166
    +    assert(mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH))



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