diff options
author | Sinny Kumari <sinny@redhat.com> | 2018-10-04 19:18:05 +0530 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-10-11 13:41:32 +0000 |
commit | c70526841e86bf72d0714db84305cd35ac62f527 (patch) | |
tree | 31965608fbe35110ffb72fac19b065004bd24580 /src/ostree/ot-builtin-refs.c | |
parent | 05e99da7a7395e80353210a576db52ba5062f1e7 (diff) | |
download | ostree-c70526841e86bf72d0714db84305cd35ac62f527.tar.gz |
src/ostree: Don't delete refs having aliases
Deleting a ref with aliases makes them dangling. In such
cases, display an error message to the user.
Fixes #1597
Signed-off-by: Sinny Kumari <sinny@redhat.com>
Closes: #1749
Approved by: cgwalters
Diffstat (limited to 'src/ostree/ot-builtin-refs.c')
-rw-r--r-- | src/ostree/ot-builtin-refs.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c index 5c2214cc..f88d08a6 100644 --- a/src/ostree/ot-builtin-refs.c +++ b/src/ostree/ot-builtin-refs.c @@ -146,8 +146,10 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab /* If we're doing aliasing, we need the full list of aliases mostly to allow * replacing existing aliases. + * If we are deleting a ref, we want to make sure that it doesn't have + * any corresponding aliases. */ - if (opt_alias) + if (opt_alias || opt_delete) { if (!ostree_repo_list_refs_ext (repo, NULL, &ref_aliases, OSTREE_REPO_LIST_REFS_EXT_ALIASES, @@ -245,7 +247,18 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab if (!ostree_parse_refspec (refspec, &remote, &ref, error)) goto out; - + + /* Look for alias if it exists for a ref we want to delete */ + GLNX_HASH_TABLE_FOREACH_KV (ref_aliases, const char *, + ref_alias, const char *, value) + { + if (!strcmp (ref, value)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Ref '%s' has an active alias: '%s'", ref, ref_alias); + goto out; + } + } if (!ostree_repo_set_ref_immediate (repo, remote, ref, NULL, cancellable, error)) goto out; |