summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-18 14:26:02 +0200
committerColin Walters (automation) <walters+githubbot@verbum.org>2016-04-19 12:28:06 +0000
commit5595664e47a483512a39a643adb54c523b77de97 (patch)
treeb149331a22743a7f0a7a34b377031a0015bc3151
parent5079f70ec07d695dc636b34728dc504426db61ea (diff)
downloadostree-5595664e47a483512a39a643adb54c523b77de97.tar.gz
ostree export: Add --prefix option
This lets you set a prefix for the resulting archive patsh. Especially useful in combination with --subpath, for instance --subpath=subdir --prefix=subdir to extract just subdir. Closes: #265 Approved by: cgwalters
-rw-r--r--src/libostree/ostree-repo-libarchive.c6
-rw-r--r--src/libostree/ostree-repo.h5
-rw-r--r--src/ostree/ot-builtin-export.c4
-rwxr-xr-xtests/test-export.sh23
4 files changed, 35 insertions, 3 deletions
diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c
index 6e6e9806..6856e94b 100644
--- a/src/libostree/ostree-repo-libarchive.c
+++ b/src/libostree/ostree-repo-libarchive.c
@@ -480,6 +480,12 @@ file_to_archive_entry_common (GFile *root,
g_autoptr(GVariant) xattrs = NULL;
time_t ts = (time_t) opts->timestamp_secs;
+ if (opts->path_prefix && opts->path_prefix[0])
+ {
+ g_autofree char *old_pathstr = pathstr;
+ pathstr = g_strconcat (opts->path_prefix, old_pathstr, NULL);
+ }
+
if (pathstr == NULL || !pathstr[0])
{
g_free (pathstr);
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 8a04e8e5..20873a05 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -610,7 +610,10 @@ typedef struct {
guint64 timestamp_secs;
guint unused_uint[8];
- gpointer unused_ptrs[8];
+
+ char *path_prefix;
+
+ gpointer unused_ptrs[7];
} OstreeRepoExportArchiveOptions;
_OSTREE_PUBLIC
diff --git a/src/ostree/ot-builtin-export.c b/src/ostree/ot-builtin-export.c
index 9a7842ab..5b84d1ab 100644
--- a/src/ostree/ot-builtin-export.c
+++ b/src/ostree/ot-builtin-export.c
@@ -33,11 +33,13 @@
static char *opt_output_path;
static char *opt_subpath;
+static char *opt_prefix;
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" },
+ { "prefix", 0, 0, G_OPTION_ARG_STRING, &opt_prefix, "Add PATH as prefix to archive pathnames", "PATH" },
{ "output", 'o', 0, G_OPTION_ARG_STRING, &opt_output_path, "Output to PATH ", "PATH" },
{ NULL }
};
@@ -132,6 +134,8 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
else
subtree = g_object_ref (root);
+ opts.path_prefix = opt_prefix;
+
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 8666e177..856c4073 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..3'
+echo '1..5'
$OSTREE checkout test2 test2-co
$OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
@@ -47,7 +47,26 @@ 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-noxattrs --prefix=the-prefix/ -o test2-prefix.tar
+mkdir t3
+(cd t3 && tar xf ../test2-prefix.tar)
+${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t3/the-prefix > diff.txt
+assert_file_empty diff.txt
+
+echo 'ok export --prefix gnutar diff (no xattrs)'
+
+cd ${test_tmpdir}
+${OSTREE} 'export' test2-noxattrs --subpath=baz --prefix=the-prefix/ -o test2-prefix-subpath.tar
+mkdir t4
+(cd t4 && tar xf ../test2-prefix-subpath.tar)
+${CMD_PREFIX} ostree --repo=repo diff --no-xattrs ./t4/the-prefix ./t/baz > diff.txt
+${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t3/the-prefix > diff.txt
+assert_file_empty diff.txt
+
+echo 'ok export --prefix --subpath gnutar diff (no xattrs)'
+
+rm test2.tar test2-subpath.tar diff.txt t t2 t3 t4 -rf
cd ${test_tmpdir}
${OSTREE} 'export' test2 -o test2.tar