checkout: Add --allow-noent option

This is useful for the gnome-ostree build system where each build is
one commit, but it's split up into /runtime /devel /debug etc. trees.
Ideally we wouldn't have a /debug subdirectory for "noarch"
components for example.

So add an option to not error out if the given path doesn't exist in
the commit.
This commit is contained in:
Colin Walters 2013-05-01 12:15:02 -04:00
parent f4327cc6a0
commit c60c70e9a9
2 changed files with 29 additions and 3 deletions

View File

@ -30,6 +30,7 @@
#include <glib/gi18n.h>
static gboolean opt_user_mode;
static gboolean opt_allow_noent;
static gboolean opt_no_triggers;
static char *opt_subpath;
static gboolean opt_union;
@ -40,6 +41,7 @@ static GOptionEntry options[] = {
{ "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, "Do not change file ownership or initialize extended attributes", NULL },
{ "subpath", 0, 0, G_OPTION_ARG_STRING, &opt_subpath, "Checkout sub-directory PATH", "PATH" },
{ "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, "Keep existing directories, overwrite existing files", NULL },
{ "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, "Do nothing if specified path does not exist", NULL },
{ "no-triggers", 0, 0, G_OPTION_ARG_NONE, &opt_no_triggers, "Don't run triggers", NULL },
{ "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, "Process many checkouts from standard input", NULL },
{ "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, "Process many checkouts from input file", NULL },
@ -89,6 +91,7 @@ process_one_checkout (OstreeRepo *repo,
{
gboolean ret = FALSE;
ProcessOneCheckoutData data;
GError *tmp_error = NULL;
ot_lobj OstreeRepoFile *root = NULL;
ot_lobj OstreeRepoFile *subtree = NULL;
ot_lobj GFileInfo *file_info = NULL;
@ -106,9 +109,21 @@ process_one_checkout (OstreeRepo *repo,
file_info = g_file_query_info ((GFile*)subtree, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
cancellable, error);
cancellable, &tmp_error);
if (!file_info)
goto out;
{
if (opt_allow_noent
&& g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_clear_error (&tmp_error);
ret = TRUE;
}
else
{
g_propagate_error (error, tmp_error);
}
goto out;
}
data.loop = g_main_loop_new (NULL, TRUE);
data.error = error;

View File

@ -19,7 +19,7 @@
set -e
echo "1..28"
echo "1..30"
. libtest.sh
@ -208,3 +208,14 @@ rm -rf test2-checkout
parent_rev_test2=$(ostree --repo=repo rev-parse test2)
${CMD_PREFIX} ostree --repo=shadow-repo checkout "${parent_rev_test2}" test2-checkout
echo "ok checkout from shadow repo"
cd ${test_tmpdir}
rm -f expected-fail
$OSTREE checkout test2 --subpath /enoent 2>/dev/null || touch expected-fail
assert_has_file expected-fail
echo "ok subdir enoent"
cd ${test_tmpdir}
$OSTREE checkout test2 --allow-noent --subpath /enoent 2>/dev/null
echo "ok subdir noent"