Skip to content

Commit

Permalink
ostree export: Accept treeish in place of commit
Browse files Browse the repository at this point in the history
If there is a commit the timestamp is set to the commit time - otherwise
it's set to 1970-01.01T00:00Z.

In the future `ostree export` could be taught to handle blobs as well.
  • Loading branch information
wmanley committed Jul 9, 2018
1 parent 66c762c commit cdfb9e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/ostree/ot-builtin-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ostree-libarchive-private.h"
#include "ostree.h"
#include "ostree-repo-file.h"
#include "ostree-cmdprivate.h"

#ifdef HAVE_LIBARCHIVE
#include <archive.h>
Expand Down Expand Up @@ -69,7 +70,7 @@ ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocatio
g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL;
gboolean ret = FALSE;
g_autoptr(GFile) root = NULL;
g_autoptr(OstreeRepoFile) root = NULL;
g_autoptr(GFile) subtree = NULL;
g_autofree char *commit = NULL;
g_autoptr(GVariant) commit_data = NULL;
Expand Down Expand Up @@ -130,22 +131,23 @@ ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocatio
if (opt_no_xattrs)
opts.disable_xattrs = TRUE;

if (!ostree_repo_read_commit (repo, rev, &root, &commit, cancellable, error))
if (!ostree_cmd__private__ ()->ostree_repo_open_file (
repo, rev, opt_subpath, OSTREE_REPO_OPEN_FILE_EXPECT_TREE, &root,
&commit, cancellable, error))
goto out;

if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit, &commit_data, error))
goto out;

opts.timestamp_secs = ostree_commit_get_timestamp (commit_data);
if (commit)
{
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit,
&commit_data, error))
goto out;

if (opt_subpath)
subtree = g_file_resolve_relative_path (root, opt_subpath);
else
subtree = g_object_ref (root);
opts.timestamp_secs = ostree_commit_get_timestamp (commit_data);
}

opts.path_prefix = opt_prefix;

if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)subtree, a,
if (!ostree_repo_export_tree_to_archive (repo, &opts, root, a,
cancellable, error))
goto out;

Expand Down
11 changes: 10 additions & 1 deletion tests/test-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set -euo pipefail

setup_test_repository "archive"

echo '1..5'
echo '1..6'

$OSTREE checkout test2 test2-co
$OSTREE commit --no-xattrs -b test2-noxattrs -s "test2 without xattrs" --tree=dir=test2-co
Expand All @@ -49,6 +49,15 @@ assert_file_empty diff.txt

echo 'ok export --subpath gnutar diff (no xattrs)'

cd ${test_tmpdir}
${OSTREE} 'export' :test2-noxattrs:baz -o test2-subpath.tar
mkdir t2a
(cd t2a && tar xf ../test2-subpath.tar)
${CMD_PREFIX} ostree --repo=repo diff --no-xattrs ./t2a ./t/baz > diff.txt
assert_file_empty diff.txt

echo 'ok export treeish gnutar diff (no xattrs)'

cd ${test_tmpdir}
${OSTREE} 'export' test2-noxattrs --prefix=the-prefix/ -o test2-prefix.tar
mkdir t3
Expand Down

0 comments on commit cdfb9e8

Please sign in to comment.