summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-18 14:17:08 +0200
committerColin Walters (automation) <walters+githubbot@verbum.org>2016-04-19 12:28:06 +0000
commit5079f70ec07d695dc636b34728dc504426db61ea (patch)
tree62176276636f057bbbb71c9a636330a19dda6162
parent9db2f43b144d130d8b6cc4aaca76eee2f4bfcacf (diff)
downloadostree-5079f70ec07d695dc636b34728dc504426db61ea.tar.gz
ostree export: Add --subpath support
This lets you export a subset of a commit. Closes: #265 Approved by: cgwalters
-rw-r--r--src/libostree/ostree-repo-libarchive.c2
-rw-r--r--src/ostree/ot-builtin-export.c10
-rwxr-xr-xtests/test-export.sh14
3 files changed, 22 insertions, 4 deletions
diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c
index 7a30192c..6e6e9806 100644
--- a/src/libostree/ostree-repo-libarchive.c
+++ b/src/libostree/ostree-repo-libarchive.c
@@ -480,7 +480,7 @@ file_to_archive_entry_common (GFile *root,
g_autoptr(GVariant) xattrs = NULL;
time_t ts = (time_t) opts->timestamp_secs;
- if (pathstr && !pathstr[0])
+ if (pathstr == NULL || !pathstr[0])
{
g_free (pathstr);
pathstr = g_strdup (".");
diff --git a/src/ostree/ot-builtin-export.c b/src/ostree/ot-builtin-export.c
index cccb50e7..9a7842ab 100644
--- a/src/ostree/ot-builtin-export.c
+++ b/src/ostree/ot-builtin-export.c
@@ -32,10 +32,12 @@
#endif
static char *opt_output_path;
+static char *opt_subpath;
static gboolean opt_no_xattrs;
static GOptionEntry options[] = {
{ "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Skip output of extended attributes", NULL },
+ { "subpath", 0, 0, G_OPTION_ARG_STRING, &opt_subpath, "Checkout sub-directory PATH", "PATH" },
{ "output", 'o', 0, G_OPTION_ARG_STRING, &opt_output_path, "Output to PATH ", "PATH" },
{ NULL }
};
@@ -60,6 +62,7 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
gboolean ret = FALSE;
const char *rev;
g_autoptr(GFile) root = NULL;
+ g_autoptr(GFile) subtree = NULL;
g_autofree char *commit = NULL;
g_autoptr(GVariant) commit_data = NULL;
struct archive *a;
@@ -124,7 +127,12 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
opts.timestamp_secs = ostree_commit_get_timestamp (commit_data);
- if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)root, a,
+ if (opt_subpath)
+ subtree = g_file_resolve_relative_path (root, opt_subpath);
+ else
+ subtree = g_object_ref (root);
+
+ if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)subtree, a,
cancellable, error))
goto out;
diff --git a/tests/test-export.sh b/tests/test-export.sh
index 1e81a2e9..8666e177 100755
--- a/tests/test-export.sh
+++ b/tests/test-export.sh
@@ -23,7 +23,7 @@ set -euo pipefail
setup_test_repository "archive-z2"
-echo '1..2'
+echo '1..3'
$OSTREE checkout test2 test2-co
$OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
@@ -35,11 +35,21 @@ mkdir t
(cd t && tar xf ../test2.tar)
${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t > diff.txt
assert_file_empty diff.txt
-rm test2.tar diff.txt t -rf
echo 'ok export gnutar diff (no xattrs)'
cd ${test_tmpdir}
+${OSTREE} 'export' test2-noxattrs --subpath=baz -o test2-subpath.tar
+mkdir t2
+(cd t2 && tar xf ../test2-subpath.tar)
+${CMD_PREFIX} ostree --repo=repo diff --no-xattrs ./t2 ./t/baz > diff.txt
+assert_file_empty diff.txt
+
+echo 'ok export --subpath gnutar diff (no xattrs)'
+
+rm test2.tar test2-subpath.tar diff.txt t t2 -rf
+
+cd ${test_tmpdir}
${OSTREE} 'export' test2 -o test2.tar
${OSTREE} commit -b test2-from-tar -s 'Import from tar' --tree=tar=test2.tar
${CMD_PREFIX} ostree --repo=repo diff test2 test2-from-tar