Commit b97d03a3 authored by Valentin David's avatar Valentin David
Browse files

buildstream/plugins/sources/local.py: Make staging deterministic.

Instead of copying metadata on files staged by local, we manually set
mode to 0755 or 0644 depending on whether user execution was enabled
on source file.

This makes file modes deterministic independently on the way source
was distributed.

Non-deterministic mode copying all metadata can still be enabled by
disable 'deterministic' Boolean configuration on the plugin.

Fixes #527.
parent be163e8d
Loading
Loading
Loading
Loading
+18 −1
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ local - stage local files and directories
"""
"""


import os
import os
import stat
from buildstream import Source, Consistency
from buildstream import Source, Consistency
from buildstream import utils
from buildstream import utils


@@ -94,12 +95,28 @@ class LocalSource(Source):
        # Dont use hardlinks to stage sources, they are not write protected
        # Dont use hardlinks to stage sources, they are not write protected
        # in the sandbox.
        # in the sandbox.
        with self.timed_activity("Staging local files at {}".format(self.path)):
        with self.timed_activity("Staging local files at {}".format(self.path)):

            if os.path.isdir(self.fullpath):
            if os.path.isdir(self.fullpath):
                utils.copy_files(self.fullpath, directory)
                files = list(utils.list_relative_paths(self.fullpath, list_dirs=True))
                utils.copy_files(self.fullpath, directory, files=files)
            else:
            else:
                destfile = os.path.join(directory, os.path.basename(self.path))
                destfile = os.path.join(directory, os.path.basename(self.path))
                files = [os.path.basename(self.path)]
                utils.safe_copy(self.fullpath, destfile)
                utils.safe_copy(self.fullpath, destfile)


            for f in files:
                path = os.path.join(directory, f)
                if os.path.islink(path):
                    pass
                elif os.path.isdir(path):
                    os.chmod(path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
                else:
                    st = os.stat(path)
                    if st.st_mode & stat.S_IXUSR:
                        os.chmod(path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
                    else:
                        os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)



# Create a unique key for a file
# Create a unique key for a file
def unique_key(filename):
def unique_key(filename):