summaryrefslogtreecommitdiff
path: root/buildstream/_ostree.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildstream/_ostree.py')
-rw-r--r--buildstream/_ostree.py241
1 files changed, 0 insertions, 241 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index dfa7567de..6fee37dc0 100644
--- a/buildstream/_ostree.py
+++ b/buildstream/_ostree.py
@@ -27,7 +27,6 @@
# pylint: disable=bad-exception-context,catching-non-exception
import os
-from collections import namedtuple
import gi
from gi.repository.GLib import Variant, VariantDict
@@ -117,80 +116,6 @@ def checkout(repo, path, commit_, user=False):
raise OSTreeError("Failed to checkout commit '{}': {}".format(commit_, e.message)) from e
-# commit():
-#
-# Commit built artifact to cache.
-#
-# Files are all recorded with uid/gid 0
-#
-# Args:
-# repo (OSTree.Repo): The repo
-# dir_ (str): The source directory to commit to the repo
-# refs (list): A list of symbolic references (tag) for the commit
-#
-def commit(repo, dir_, refs):
-
- def commit_filter(repo, path, file_info):
-
- # For now, just set everything in the repo as uid/gid 0
- #
- # In the future we'll want to extract virtualized file
- # attributes from a fuse layer and use that.
- #
- file_info.set_attribute_uint32('unix::uid', 0)
- file_info.set_attribute_uint32('unix::gid', 0)
-
- return OSTree.RepoCommitFilterResult.ALLOW
-
- commit_modifier = OSTree.RepoCommitModifier.new(
- OSTree.RepoCommitModifierFlags.NONE, commit_filter)
-
- repo.prepare_transaction()
- try:
- # add tree to repository
- mtree = OSTree.MutableTree.new()
- repo.write_directory_to_mtree(Gio.File.new_for_path(dir_),
- mtree, commit_modifier)
- _, root = repo.write_mtree(mtree)
-
- # create root commit object, no parent, no branch
- _, rev = repo.write_commit(None, None, None, None, root)
-
- # create refs
- for ref in refs:
- repo.transaction_set_ref(None, ref, rev)
-
- # complete repo transaction
- repo.commit_transaction(None)
- except GLib.GError as e:
-
- # Reraise any error as a buildstream error
- repo.abort_transaction()
- raise OSTreeError(e.message) from e
-
-
-# set_ref():
-#
-# Set symbolic reference to specified revision.
-#
-# Args:
-# repo (OSTree.Repo): The repo
-# ref (str): A symbolic reference (tag) for the commit
-# rev (str): Commit checksum
-#
-def set_ref(repo, ref, rev):
-
- repo.prepare_transaction()
- try:
- repo.transaction_set_ref(None, ref, rev)
-
- # complete repo transaction
- repo.commit_transaction(None)
- except:
- repo.abort_transaction()
- raise
-
-
# exists():
#
# Checks wether a given commit or symbolic ref exists and
@@ -244,172 +169,6 @@ def checksum(repo, ref):
return checksum_
-OSTREE_GIO_FAST_QUERYINFO = ("standard::name,standard::type,standard::size,"
- "standard::is-symlink,standard::symlink-target,"
- "unix::device,unix::inode,unix::mode,unix::uid,"
- "unix::gid,unix::rdev")
-
-
-DiffItem = namedtuple('DiffItem', ['src', 'src_info',
- 'target', 'target_info',
- 'src_checksum', 'target_checksum'])
-
-
-# diff_dirs():
-#
-# Compute the difference between directory a and b as 3 separate sets
-# of OSTree.DiffItem.
-#
-# This is more-or-less a direct port of OSTree.diff_dirs (which cannot
-# be used via PyGobject), but does not support options.
-#
-# Args:
-# a (Gio.File): The first directory for the comparison.
-# b (Gio.File): The second directory for the comparison.
-#
-# Returns:
-# (modified, removed, added)
-#
-def diff_dirs(a, b):
- # get_file_checksum():
- #
- # Helper to compute the checksum of an arbitrary file (different
- # objects have different methods to compute these).
- #
- def get_file_checksum(f, f_info):
- if isinstance(f, OSTree.RepoFile):
- return f.get_checksum()
- else:
- contents = None
- if f_info.get_file_type() == Gio.FileType.REGULAR:
- contents = f.read()
-
- csum = OSTree.checksum_file_from_input(f_info, None, contents,
- OSTree.ObjectType.FILE)
- return OSTree.checksum_from_bytes(csum)
-
- # diff_files():
- #
- # Helper to compute a diff between two files.
- #
- def diff_files(a, a_info, b, b_info):
- checksum_a = get_file_checksum(a, a_info)
- checksum_b = get_file_checksum(b, b_info)
-
- if checksum_a != checksum_b:
- return DiffItem(a, a_info, b, b_info, checksum_a, checksum_b)
-
- return None
-
- # diff_add_dir_recurse():
- #
- # Helper to collect all files in a directory recursively.
- #
- def diff_add_dir_recurse(d):
- added = []
-
- dir_enum = d.enumerate_children(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
-
- for child_info in dir_enum:
- name = child_info.get_name()
- child = d.get_child(name)
- added.append(child)
-
- if child_info.get_file_type() == Gio.FileType.DIRECTORY:
- added.extend(diff_add_dir_recurse(child))
-
- return added
-
- modified = []
- removed = []
- added = []
-
- child_a_info = a.query_info(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
- child_b_info = b.query_info(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
-
- # If both are directories and have the same checksum, we know that
- # none of the underlying files changed, so we can save time.
- if (child_a_info.get_file_type() == Gio.FileType.DIRECTORY and
- child_b_info.get_file_type() == Gio.FileType.DIRECTORY and
- isinstance(a, OSTree.RepoFileClass) and
- isinstance(b, OSTree.RepoFileClass)):
- if a.tree_get_contents_checksum() == b.tree_get_contents_checksum():
- return modified, removed, added
-
- # We walk through 'a' first
- dir_enum = a.enumerate_children(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
- for child_a_info in dir_enum:
- name = child_a_info.get_name()
-
- child_a = a.get_child(name)
- child_a_type = child_a_info.get_file_type()
-
- try:
- child_b = b.get_child(name)
- child_b_info = child_b.query_info(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
- except GLib.Error as e:
- # If the file does not exist in b, it has been removed
- if e.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_FOUND):
- removed.append(child_a)
- continue
- else:
- raise
-
- # If the files differ but are of different types, we report a
- # modification, saving a bit of time because we won't need a
- # checksum
- child_b_type = child_b_info.get_file_type()
- if child_a_type != child_b_type:
- diff_item = DiffItem(child_a, child_a_info,
- child_b, child_b_info,
- None, None)
- modified.append(diff_item)
- # Finally, we compute checksums and compare the file contents directly
- else:
- diff_item = diff_files(child_a, child_a_info, child_b, child_b_info)
-
- if diff_item:
- modified.append(diff_item)
-
- # If the files are both directories, we recursively use
- # this function to find differences - saving time if they
- # are equal.
- if child_a_type == Gio.FileType.DIRECTORY:
- subdir = diff_dirs(child_a, child_b)
- modified.extend(subdir[0])
- removed.extend(subdir[1])
- added.extend(subdir[2])
-
- # Now we walk through 'b' to find any files that were added
- dir_enum = b.enumerate_children(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
- for child_b_info in dir_enum:
- name = child_b_info.get_name()
-
- child_b = b.get_child(name)
-
- try:
- child_a = a.get_child(name)
- child_a_info = child_a.query_info(OSTREE_GIO_FAST_QUERYINFO,
- Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)
- except GLib.Error as e:
- # If the file does not exist in 'a', it was added.
- if e.matches(Gio.io_error_quark(), Gio.IOErrorEnum.NOT_FOUND):
- added.append(child_b)
- if child_b_info.get_file_type() == Gio.FileType.DIRECTORY:
- added.extend(diff_add_dir_recurse(child_b))
- continue
- else:
- raise
-
- return modified, removed, added
-
-
# fetch()
#
# Fetch new objects from a remote, if configured