Skip to content

Commit

Permalink
dorothy, symlink-helper: fix alpine symlink failures
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Oct 15, 2024
1 parent 5def66e commit acee8c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 14 additions & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ function dorothy_() (
uname -r | grep --quiet --ignore-case --fixed-strings --regexp='manjaro'
}

# see [commands/is-alpine] for details
function __is_alpine {
test -f /etc/os-release && grep --quiet --ignore-case --regexp='ID=alpine' /etc/os-release 2>/dev/null;
}

# see [commands/fs-realpath] for details
function __fs_realpath {
# options
Expand Down Expand Up @@ -638,7 +643,15 @@ function dorothy_() (
function relocate_then_symlink_if_necessary {
local symlink="$1" destination="$2"
relocate_if_necessary "$symlink" "$destination"
ln -sfF "$destination" "$symlink"
if __is_alpine; then
# alpine doesn't support -F, however the removals of relocate_if_necessary should make it unnecessary
ln -sf "$destination" "$symlink"
else
# -F: replace symlink if directory if needed
# -f: unlink symlink path if needed
# -s: symbolic link
ln -sfF "$destination" "$symlink"
fi
# cleanup accidents
symlink="$symlink/$(basename "$destination")"
if test -L "$symlink"; then
Expand Down
13 changes: 11 additions & 2 deletions commands/symlink-helper
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,22 @@ function symlink_helper() (
# not a symlink, confirm with the user what to do
fs-rm --confirm -- "$option_symlink"
fi
elif test -L "$option_symlink"; then
# is a broken symlink, drop it and recreate
rm "$option_symlink"
fi

# create the symlink
# -F: replace symlink if directory if needed
# -f: unlink symlink path if needed
# -s: symbolik link
ln -sfF "$option_existing" "$option_symlink"
# -s: symbolic link
if is-alpine; then
# alpine doesn't support -F, however the above removals should make it unnecessary
# https://github.com/bevry/dorothy/actions/runs/11323459946/job/31486170602#step:4:11
ln -sf "$option_existing" "$option_symlink"
else
ln -sfF "$option_existing" "$option_symlink"
fi

# log result to stderr
echo-style --success="👍 Symlink created at " --code="$option_symlink" --bold=" targetting " --code="$option_existing"
Expand Down

0 comments on commit acee8c9

Please sign in to comment.