[ostree] core: Add "subpath" option to checkout



commit 4db485dd5ff207292768a7dede2b336dba2d38de
Author: Colin Walters <walters verbum org>
Date:   Tue Mar 6 08:57:31 2012 -0500

    core: Add "subpath" option to checkout
    
    Will be used by ostbuild to extract e.g. /runtime or /devel from
    artifacts.

 src/ostree/ot-builtin-checkout.c |   23 ++++++++++++++++++-----
 tests/t0000-basic.sh             |    8 +++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c
index e7cc20a..f473072 100644
--- a/src/ostree/ot-builtin-checkout.c
+++ b/src/ostree/ot-builtin-checkout.c
@@ -28,9 +28,11 @@
 #include <glib/gi18n.h>
 
 static gboolean user_mode;
+static char *subpath;
 
 static GOptionEntry options[] = {
   { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &user_mode, "Do not change file ownership or initialze extended attributes", NULL },
+  { "subpath", 0, 0, G_OPTION_ARG_STRING, &subpath, "Checkout sub-directory PATH", "PATH" },
   { NULL }
 };
 
@@ -45,7 +47,8 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   char *resolved_commit = NULL;
   const char *destination;
   OstreeRepoFile *root = NULL;
-  GFileInfo *root_info = NULL;
+  OstreeRepoFile *subtree = NULL;
+  GFileInfo *file_info = NULL;
   GFile *destf = NULL;
 
   context = g_option_context_new ("COMMIT DESTINATION - Check out a commit into a filesystem tree");
@@ -80,14 +83,23 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   if (!ostree_repo_file_ensure_resolved (root, error))
     goto out;
 
-  root_info = g_file_query_info ((GFile*)root, OSTREE_GIO_FAST_QUERYINFO,
+  if (subpath)
+    {
+      subtree = (OstreeRepoFile*)g_file_resolve_relative_path ((GFile*)root, subpath);
+    }
+  else
+    {
+      subtree = g_object_ref (root);
+    }
+
+  file_info = g_file_query_info ((GFile*)subtree, OSTREE_GIO_FAST_QUERYINFO,
                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                  cancellable, error);
-  if (!root_info)
+  if (!file_info)
     goto out;
 
   if (!ostree_repo_checkout_tree (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
-                                  destf, root, root_info, cancellable, error))
+                                  destf, subtree, file_info, cancellable, error))
     goto out;
 
   ret = TRUE;
@@ -98,6 +110,7 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   g_clear_object (&repo);
   g_clear_object (&destf);
   g_clear_object (&root);
-  g_clear_object (&root_info);
+  g_clear_object (&subtree);
+  g_clear_object (&file_info);
   return ret;
 }
diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh
index bffed6f..606ef38 100755
--- a/tests/t0000-basic.sh
+++ b/tests/t0000-basic.sh
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..26"
+echo "1..27"
 
 . libtest.sh
 
@@ -190,3 +190,9 @@ cd ${test_tmpdir}
 $OSTREE cat test2 /yet/another/tree/green > greenfile-contents
 assert_file_has_content greenfile-contents "leaf"
 echo "ok cat-file"
+
+cd ${test_tmpdir}
+$OSTREE checkout --subpath /yet/another test2 checkout-test2-subpath
+cd checkout-test2-subpath
+assert_file_has_content tree/green "leaf"
+echo "ok checkout subpath"



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