minimal/do: fix a bug when $PWD != $(/bin/pwd).

This can happen when $PWD contains a symlink somewhere in the path.  In
that case, "cd ..; cat x" could mean something different from "cat ../x".

Notably, this error occurs when running "./do test" if your build
directory is through a symlink.  For example, on freebsd your home
directory is /home/$USER, but /home is a symlink to /usr/home, which
triggers this problem.

Not adding tests in this commit, because when I added some tests, I
found even more symlink-related bugs, but those ones are much more
unlikely to occur.  The additional fixes+tests are in a later commit.
This commit is contained in:
Avery Pennarun 2018-12-17 13:50:33 +00:00
commit 9aa8061e83
2 changed files with 9 additions and 3 deletions

2
do
View file

@ -24,7 +24,7 @@ usage() {
}
mydir=$(dirname "$0")
cd "$mydir" || die "can't find self in dir: $mydir"
cd "$(/bin/pwd)" && cd "$mydir" || die "can't find self in dir: $mydir"
args=
while [ "$1" != "${1#-}" ]; do