Skip to content

Commit

Permalink
fixup! lib/checkout: support filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebon committed Feb 2, 2018
1 parent 654add0 commit 02dba1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
32 changes: 13 additions & 19 deletions src/libostree/ostree-repo-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,17 +1032,6 @@ checkout_tree_at_recurse (OstreeRepo *self,
return TRUE;
}

static GString*
new_canonicalized_path_buf (const char *path)
{
GString *buf = g_string_new (path);
g_assert_cmpint (buf->len, >, 0);
/* Ensure it ends with / */
if (buf->str[buf->len-1] != '/')
g_string_append_c (buf, '/');
return buf;
}

/* Begin a checkout process */
static gboolean
checkout_tree_at (OstreeRepo *self,
Expand All @@ -1057,26 +1046,31 @@ checkout_tree_at (OstreeRepo *self,
g_auto(CheckoutState) state = { 0, };

if (options->filter)
state.path_buf = new_canonicalized_path_buf (options->subpath);
state.path_buf = g_string_new ("/");

/* If SELinux labeling is enabled, we need to keep track of the full path string */
if (options->sepolicy)
{
/* Otherwise it'd just be corrupting things, and there's no use case */
g_assert (options->force_copy);

if (options->sepolicy_prefix || !state.path_buf)
{
state.selabel_path_buf =
new_canonicalized_path_buf (options->sepolicy_prefix ?: options->subpath);
state.shared_path_buf = FALSE;
}
else
const char *prefix = options->sepolicy_prefix ?: options->subpath;
if (g_str_equal (prefix, "/") && state.path_buf)
{
/* just use the same scratchpad if we can */
state.selabel_path_buf = state.path_buf;
state.shared_path_buf = TRUE;
}
else
{
GString *buf = g_string_new (prefix);
g_assert_cmpint (buf->len, >, 0);
/* Ensure it ends with / */
if (buf->str[buf->len-1] != '/')
g_string_append_c (buf, '/');
state.selabel_path_buf = buf;
state.shared_path_buf = FALSE;
}
}

/* Special case handling for subpath of a non-directory */
Expand Down
4 changes: 2 additions & 2 deletions tests/basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ echo "ok checkout skip-list"
cd ${test_tmpdir}
rm -rf checkout-test2-skiplist
cat > test-skiplist.txt <<EOF
/baz/saucer
/baz/deeper
/saucer
/deeper
EOF
$OSTREE checkout --skip-list test-skiplist.txt --subpath /baz \
test2 checkout-test2-skiplist
Expand Down
2 changes: 1 addition & 1 deletion tests/installed/itest-label-selinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ echo "ok checkout with sepolicy and selinux-prefix"

# Now check that combining --selinux-policy with --skip-list doesn't blow up
echo > skip-list.txt << EOF
/subdir/usr/bin/true
/usr/bin/true
EOF
ostree checkout testbranch --selinux-policy / --skip-list skip-list.txt \
--subpath subdir --selinux-prefix / co
Expand Down

0 comments on commit 02dba1d

Please sign in to comment.