alpine-baselayout pre-upgrade script erroneously detects that /var/run is a directory when it is actually a symlink
The pre upgrade script is trying to convert /var/run from a directory to a symlink that points to /run. To determine if /var/run is a directory the script is doing:
if [ -d /var/run]; then
do conversion stuff....
fi
Here is a link to the pre-upgrade script I am looking at: https://git.alpinelinux.org/aports/tree/main/alpine-baselayout/alpine-baselayout.pre-upgrade#n18
test -d is erroneriously reporting that /var/run is a directory when it is actually a symlink.
Here are the steps to reproduce:
# Pull the latest alpine:3 container
ubuntu@docker:~$ docker pull alpine:3
3: Pulling from library/alpine
b3c136eddcbf: Pull complete
Digest: sha256:686d8c9dfa6f3ccfc8230bc3178d23f84eeaf7e457f36f271ab1acc53015037c
Status: Downloaded newer image for alpine:3
docker.io/library/alpine:3
# Get a shell on the alpine:3 container
ubuntu@docker:~$ docker run -it alpine:3 sh
# Check the alpine-baselayout version
/ # apk version alpine-baselayout 2>/dev/null
Installed: Available:
alpine-baselayout-3.2.0-r20 ?
# Test is /var/run is a directory
/ # if [ -d /var/run ]; then echo 'true'; fi
true
# Test is /var/run is a symlink
/ # if [ -L /var/run ]; then echo 'true'; fi
true
# do a ls of /var and see that /var/run is actually a symlink.
/ # ls -l /var | grep run
lrwxrwxrwx 1 root root 4 May 23 16:53 run -> /run
# run upgrade
/ # apk upgrade
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/aarch64/APKINDEX.tar.gz
(1/2) Upgrading alpine-baselayout-data (3.2.0-r20 -> 3.2.0-r21)
(2/2) Upgrading alpine-baselayout (3.2.0-r20 -> 3.2.0-r21)
Executing alpine-baselayout-3.2.0-r21.pre-upgrade
Executing alpine-baselayout-3.2.0-r21.post-upgrade
Executing busybox-1.35.0-r13.trigger
OK: 5 MiB in 14 packages
# See that nothing has changed with /var/run
/ # ls -l /var | grep run
lrwxrwxrwx 1 root root 4 Jun 7 18:59 run -> /run