lib/repo: Import metadata via hardlink even for distinct repo modes
authorColin Walters <walters@verbum.org>
Mon, 12 Jun 2017 17:38:52 +0000 (13:38 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 13 Jun 2017 12:02:12 +0000 (12:02 +0000)
Our previous logic for import-via-hardlink only tried if the repo modes match,
but we *can* hardlink metadata between e.g. `archive` and `bare-user` repos, and
that's quite useful thing to do. Our documentation encourages converting to/from
those repo modes locally for build systems.

Closes: #922
Approved by: alexlarsson

src/libostree/ostree-repo.c
tests/basic-test.sh

index e43d4dcdbcedf6e2a713250406333b9eab4e900f..33ca0ae8fc59d9304b557b257f19186e9921d8bb 100644 (file)
@@ -3143,6 +3143,23 @@ ostree_repo_import_object_from (OstreeRepo           *self,
                                                checksum, TRUE, cancellable, error);
 }
 
+static gboolean
+import_via_hardlink_is_possible (OstreeRepo *src_repo,
+                                 OstreeRepo *dest_repo,
+                                 OstreeObjectType objtype)
+{
+  /* We need the ability to make hardlinks */
+  if (src_repo->owner_uid != dest_repo->owner_uid)
+    return FALSE;
+  /* Equal modes are always compatible */
+  if (src_repo->mode == dest_repo->mode)
+    return TRUE;
+  /* Metadata is identical between all modes */
+  if (OSTREE_OBJECT_TYPE_IS_META (objtype))
+    return TRUE;
+  return FALSE;
+}
+
 /**
  * ostree_repo_import_object_from_with_trust:
  * @self: Destination repo
@@ -3174,9 +3191,7 @@ ostree_repo_import_object_from_with_trust (OstreeRepo           *self,
    * repository modes to match, as well as the owner uid (since we need to be
    * able to make hardlinks).
    */
-  if (trusted &&
-      self->mode == source->mode &&
-      self->owner_uid == source->owner_uid)
+  if (trusted && import_via_hardlink_is_possible (source, self, objtype))
     {
       gboolean hardlink_was_supported = FALSE;
 
index e3e442e9bd22b0ab8573d35319004f43531235b3..f6aa72c2b601c229e7bc3f48027989d81ee7a194 100644 (file)
@@ -254,9 +254,18 @@ echo "ok diff file changing type"
 
 cd ${test_tmpdir}
 mkdir repo2
-ostree_repo_init repo2 --mode=bare-user
+# Use a different mode to test hardlinking metadata only
+if grep -q 'mode=archive' repo/config || is_bare_user_only_repo repo; then
+    opposite_mode=bare-user
+else
+    opposite_mode=archive
+fi
+ostree_repo_init repo2 --mode=$opposite_mode
 ${CMD_PREFIX} ostree --repo=repo2 pull-local repo
-echo "ok pull-local"
+test2_commitid=$(${CMD_PREFIX} ostree --repo=repo rev-parse test2)
+test2_commit_relpath=/objects/${test2_commitid:0:2}/${test2_commitid:2}.commit
+assert_files_hardlinked repo/${test2_commit_relpath} repo2/${test2_commit_relpath}
+echo "ok pull-local (hardlinking metadata)"
 
 cd ${test_tmpdir}
 ${CMD_PREFIX} ostree --repo=repo2 checkout ${CHECKOUT_U_ARG} test2 test2-checkout-from-local-clone