Commit 39d66adf authored by Ed Baunton's avatar Ed Baunton
Browse files

remote.py: expressly chmod downloaded file

Instead of leaving the permissioning of downloaded file in remote.py up
to the user's umask; expressly set permissions to 0644 or 0755 if
executable
parent 1ba92c1a
Loading
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ remote - stage files from remote urls

"""
import os
import stat
from buildstream import SourceError, utils
from ._downloadablefilesource import DownloadableFileSource

@@ -85,9 +84,12 @@ class RemoteSource(DownloadableFileSource):

            utils.safe_copy(self._get_mirror_file(), dest)

            # To prevent user's umask introducing variability here, explicitly set
            # file modes.
            if self.executable:
                st = os.stat(dest)
                os.chmod(dest, st.st_mode | stat.S_IEXEC)
                os.chmod(dest, 0o755)
            else:
                os.chmod(dest, 0o644)


def setup():
+9 −4
Original line number Diff line number Diff line
@@ -86,7 +86,11 @@ def test_simple_file_build(cli, tmpdir, datafiles):
    checkout_file = os.path.join(checkoutdir, 'file')
    assert(os.path.exists(checkout_file))

    assert(not (os.stat(checkout_file).st_mode & stat.S_IEXEC))
    mode = os.stat(checkout_file).st_mode
    # Assert not executable by anyone
    assert(not (mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)))
    # Assert not writeable by anyone other than me
    assert(not (mode & (stat.S_IWGRP | stat.S_IWOTH)))


@pytest.mark.datafiles(os.path.join(DATA_DIR, 'single-file-custom-name'))
@@ -156,6 +160,7 @@ def test_executable(cli, tmpdir, datafiles):
    result = cli.run(project=project, args=[
        'checkout', 'target-custom-executable.bst', checkoutdir
    ])

    assert (os.stat(
        os.path.join(checkoutdir, 'some-custom-file')).st_mode & stat.S_IEXEC)
    mode = os.stat(os.path.join(checkoutdir, 'some-custom-file')).st_mode
    assert (mode & stat.S_IEXEC)
    # Assert executable by anyone
    assert(mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH))