diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-04-05 20:10:03 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-04-05 20:10:03 +0900 |
commit | 21b6314b33358960b4f0b63c708d510bdd755fbc (patch) | |
tree | fa52ab58bce435afb679bce0b8fd0a1053ab1d17 /buildstream/_ostree.py | |
parent | 76a6aae5509fd0269f09d913748d068c3c9d288b (diff) | |
download | buildstream-21b6314b33358960b4f0b63c708d510bdd755fbc.tar.gz |
_ostree.py: Changes to repository modes.
We use ostree primarily for the artifact cache and also for
the ostree source plugin, for the artifact cache, we want "bare user"
mode repository.
Changes are that:
o We no longer encode files as uid/gid root, because it requires "user mode"
option at checkout time
o We no longer use "user mode" option when checking out the artifacts (but
we still need to use it for the ostree source).
This is all because checking out with "user mode" not only drops the ownership
bits on the checked out files, but it _also_ munges the permission bits, we
need the file permission bits to be preserved.
Diffstat (limited to 'buildstream/_ostree.py')
-rw-r--r-- | buildstream/_ostree.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py index 73259319c..7952cb5fc 100644 --- a/buildstream/_ostree.py +++ b/buildstream/_ostree.py @@ -63,8 +63,9 @@ def ensure(path, compress): # repo (OSTree.Repo): The repo # path (str): The checkout path # commit (str): The commit checksum to checkout +# user (boot): Whether to checkout in user mode # -def checkout(repo, path, commit): +def checkout(repo, path, commit, user=False): # Check out a full copy of an OSTree at a given ref to some directory. # @@ -78,14 +79,21 @@ def checkout(repo, path, commit): # ostree --repo=repo checkout --user-mode runtime/org.freedesktop.Sdk/x86_64/1.4 foo os.makedirs(os.path.dirname(path), exist_ok=True) - # ignore uid/gid to allow checkout as non-root options = OSTree.RepoCheckoutAtOptions() - options.mode = OSTree.RepoCheckoutMode.USER - # XXX How come this works if we give the CWD as the - # file descriptor of the directory os.path.dirname(path) ? + # For repos which contain root owned files, we need + # to checkout with OSTree.RepoCheckoutMode.USER # - # from fcntl.h + # This will reassign uid/gid and also munge the + # permission bits a bit. + if user: + options.mode = OSTree.RepoCheckoutMode.USER + + # Using AT_FDCWD value from fcntl.h + # + # This will be ignored if the passed path is an absolute path, + # if path is a relative path then it will be appended to the + # current working directory. AT_FDCWD = -100 try: repo.checkout_at(options, AT_FDCWD, path, commit) @@ -106,10 +114,17 @@ def checkout(repo, path, commit): # def commit(repo, dir, ref): - # We commit everything with uid/gid 0 def commit_filter(repo, path, file_info): - file_info.set_attribute_uint32('unix::uid', 0) - file_info.set_attribute_uint32('unix::gid', 0) + + # If we wanted to commit as uid/gid root, then + # we would set the following in this filter: + # + # file_info.set_attribute_uint32('unix::uid', 0) + # file_info.set_attribute_uint32('unix::gid', 0) + # + # We don't do this because ostree user mode checkouts + # not only munge the ownership bits but _also_ the permission + # bits. return OSTree.RepoCommitFilterResult.ALLOW commit_modifier = OSTree.RepoCommitModifier.new( |