Skip to content

Commit

Permalink
Make --symlink idempotent
Browse files Browse the repository at this point in the history
When creating symlinks specified with --symlink, check errno if
creation fails. If the reason was EEXIST, check the path of the
existing symlink. If it matches what was desired, continue as
normal.

Signed-off-by: Jakob Kaivo <jkk@ung.org>
  • Loading branch information
jkaivo committed Apr 21, 2023
1 parent 9286389 commit b1efc1e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bubblewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,20 @@ setup_newroot (bool unshare_pid,
case SETUP_MAKE_SYMLINK:
assert (op->source != NULL); /* guaranteed by the constructor */
if (symlink (op->source, dest) != 0)
{
if (errno == EEXIST)
{
char existing[PATH_MAX] = "";
readlink (dest, existing, sizeof (existing));
if (strcmp(existing, op->source) == 0)
{
break;
}
die_with_error ("Can't make symlink at %s (existing symlink points to %s)",
op->dest, existing);
}
die_with_error ("Can't make symlink at %s", op->dest);
}
break;

case SETUP_SET_HOSTNAME:
Expand Down

0 comments on commit b1efc1e

Please sign in to comment.