ostree export: Add --subpath support
This lets you export a subset of a commit. Closes: #265 Approved by: cgwalters
This commit is contained in:
parent
9db2f43b14
commit
5079f70ec0
|
|
@ -480,7 +480,7 @@ file_to_archive_entry_common (GFile *root,
|
||||||
g_autoptr(GVariant) xattrs = NULL;
|
g_autoptr(GVariant) xattrs = NULL;
|
||||||
time_t ts = (time_t) opts->timestamp_secs;
|
time_t ts = (time_t) opts->timestamp_secs;
|
||||||
|
|
||||||
if (pathstr && !pathstr[0])
|
if (pathstr == NULL || !pathstr[0])
|
||||||
{
|
{
|
||||||
g_free (pathstr);
|
g_free (pathstr);
|
||||||
pathstr = g_strdup (".");
|
pathstr = g_strdup (".");
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *opt_output_path;
|
static char *opt_output_path;
|
||||||
|
static char *opt_subpath;
|
||||||
static gboolean opt_no_xattrs;
|
static gboolean opt_no_xattrs;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
{ "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Skip output of extended attributes", NULL },
|
{ "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" },
|
{ "output", 'o', 0, G_OPTION_ARG_STRING, &opt_output_path, "Output to PATH ", "PATH" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
@ -60,6 +62,7 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
const char *rev;
|
const char *rev;
|
||||||
g_autoptr(GFile) root = NULL;
|
g_autoptr(GFile) root = NULL;
|
||||||
|
g_autoptr(GFile) subtree = NULL;
|
||||||
g_autofree char *commit = NULL;
|
g_autofree char *commit = NULL;
|
||||||
g_autoptr(GVariant) commit_data = NULL;
|
g_autoptr(GVariant) commit_data = NULL;
|
||||||
struct archive *a;
|
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);
|
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))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ set -euo pipefail
|
||||||
|
|
||||||
setup_test_repository "archive-z2"
|
setup_test_repository "archive-z2"
|
||||||
|
|
||||||
echo '1..2'
|
echo '1..3'
|
||||||
|
|
||||||
$OSTREE checkout test2 test2-co
|
$OSTREE checkout test2 test2-co
|
||||||
$OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
|
$OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
|
||||||
|
|
@ -35,10 +35,20 @@ mkdir t
|
||||||
(cd t && tar xf ../test2.tar)
|
(cd t && tar xf ../test2.tar)
|
||||||
${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t > diff.txt
|
${CMD_PREFIX} ostree --repo=repo diff --no-xattrs test2-noxattrs ./t > diff.txt
|
||||||
assert_file_empty diff.txt
|
assert_file_empty diff.txt
|
||||||
rm test2.tar diff.txt t -rf
|
|
||||||
|
|
||||||
echo 'ok export gnutar diff (no xattrs)'
|
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}
|
cd ${test_tmpdir}
|
||||||
${OSTREE} 'export' test2 -o test2.tar
|
${OSTREE} 'export' test2 -o test2.tar
|
||||||
${OSTREE} commit -b test2-from-tar -s 'Import from tar' --tree=tar=test2.tar
|
${OSTREE} commit -b test2-from-tar -s 'Import from tar' --tree=tar=test2.tar
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue