Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete refs having aliases #1749

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ostree/ot-builtin-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/test-refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ done
${CMD_PREFIX} ostree --repo=repo refs -A > refs.txt
assert_file_has_content_literal refs.txt 'exampleos/x86_64/stable/server -> exampleos/x86_64/27/server'

# Test that we don't delete a ref having aliases
if ${CMD_PREFIX} ostree --repo=repo refs --delete exampleos/x86_64/27/server; then
assert_not_reached "refs --delete unexpectedly succeeded in deleting a ref containing alias!"
fi

${CMD_PREFIX} ostree --repo=repo summary -u

echo "ok ref symlink"
Expand Down