[ostree] pull: Support --mirror option



commit 6a5e66b1521a153d0d3b6a27999c8a320be855fa
Author: Colin Walters <walters verbum org>
Date:   Mon Jun 16 17:11:50 2014 -0400

    pull: Support --mirror option
    
    There's several use cases for calling into ostree itself to do
    mirroring, instead of using bare rsync.  For example, it's a bit more
    efficient as it doesn't require syncing the objects/ directory.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728351

 src/libostree/ostree-repo-pull.c |    4 ++--
 src/libostree/ostree-repo.h      |    4 +++-
 src/ostree/ot-builtin-pull.c     |    5 +++++
 tests/pull-test.sh               |    9 +++++++++
 4 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index 467d27e..dbcdc40 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1262,8 +1262,8 @@ ostree_repo_pull (OstreeRepo               *self,
         }
       else
         {
-          ostree_repo_transaction_set_ref (pull_data->repo, pull_data->remote_name, ref, checksum);
-
+          gboolean is_mirror = (pull_data->flags & OSTREE_REPO_PULL_FLAGS_MIRROR) > 0;
+          ostree_repo_transaction_set_ref (pull_data->repo, is_mirror ? NULL : pull_data->remote_name, ref, 
checksum);
         }
     }
 
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 562e6c1..ccd9f40 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -510,9 +510,11 @@ gboolean ostree_repo_prune (OstreeRepo        *self,
 /**
  * OstreeRepoPullFlags:
  * @OSTREE_REPO_PULL_FLAGS_NONE: No special options for pull
+ * @OSTREE_REPO_PULL_FLAGS_MIRROR: Write out refs suitable for mirrors
  */
 typedef enum {
-  OSTREE_REPO_PULL_FLAGS_NONE
+  OSTREE_REPO_PULL_FLAGS_NONE,
+  OSTREE_REPO_PULL_FLAGS_MIRROR
 } OstreeRepoPullFlags;
 
 gboolean ostree_repo_pull (OstreeRepo             *self,
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 4ed1a15..1cf3bb7 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -28,9 +28,11 @@
 #include "otutil.h"
 
 static gboolean opt_disable_fsync;
+static gboolean opt_mirror;
 
 static GOptionEntry options[] = {
   { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
+  { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Write refs suitable for a mirror", NULL },
   { NULL }
 };
 
@@ -60,6 +62,9 @@ ostree_builtin_pull (int argc, char **argv, OstreeRepo *repo, GCancellable *canc
   if (opt_disable_fsync)
     ostree_repo_set_disable_fsync (repo, TRUE);
 
+  if (opt_mirror)
+    pullflags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
+
   if (strchr (argv[1], ':') == NULL)
     {
       remote = g_strdup (argv[1]);
diff --git a/tests/pull-test.sh b/tests/pull-test.sh
index 8231cef..dc92e97 100755
--- a/tests/pull-test.sh
+++ b/tests/pull-test.sh
@@ -37,6 +37,15 @@ assert_file_has_content baz/cow '^moo$'
 echo "ok pull contents"
 
 cd ${test_tmpdir}
+mkdir mirrorrepo
+ostree --repo=mirrorrepo init --mode=archive-z2
+${CMD_PREFIX} ostree --repo=mirrorrepo remote add --set=gpg-verify=false origin $(cat 
httpd-address)/ostree/gnomerepo
+${CMD_PREFIX} ostree --repo=mirrorrepo pull --mirror origin main
+${CMD_PREFIX} ostree --repo=mirrorrepo fsck
+$OSTREE show main >/dev/null
+echo "ok pull mirror"
+
+cd ${test_tmpdir}
 ostree --repo=ostree-srv/gnomerepo commit -b main -s "Metadata string" 
--add-detached-metadata-string=SIGNATURE=HANCOCK --tree=ref=main
 ${CMD_PREFIX} ostree --repo=repo pull origin main
 ${CMD_PREFIX} ostree --repo=repo fsck


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]