Import PoC
This commit is contained in:
parent
21b68007ef
commit
256ef33bdf
2 changed files with 45 additions and 0 deletions
10
realpath.sh
Executable file
10
realpath.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
p="$1"
|
||||||
|
target=$(readlink "$p")
|
||||||
|
|
||||||
|
case "$target" in
|
||||||
|
/*) p="$target";;
|
||||||
|
*) p="${p%/*}/$target";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf "%s\n" "$p"|sed -e 's@/[^/]*/\.\.\(/\|$\)@/@g' -e 's|/\.\(/\|$\)|/|g' -e 's|/$||g'
|
35
test.sh
Executable file
35
test.sh
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/sh
|
||||||
|
bin=$PWD/realpath.sh
|
||||||
|
dir="$(mktemp -d)"
|
||||||
|
cd "$dir"
|
||||||
|
|
||||||
|
do_test() {
|
||||||
|
name=$dir/$2
|
||||||
|
target=$3
|
||||||
|
case "$name" in
|
||||||
|
*/*) mkdir -p "${name%/*}";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ln -s "$target" "$name"
|
||||||
|
|
||||||
|
is=$($bin "$name")
|
||||||
|
|
||||||
|
should=$(readlink -f "$name")
|
||||||
|
|
||||||
|
if [ "$is" == "$should" ]; then
|
||||||
|
echo "Test $1 success"
|
||||||
|
else
|
||||||
|
echo "Test $1 fail: \"${bin##*/} $name\" returned \"$is\" instead of \"$should\""
|
||||||
|
stat "$name"
|
||||||
|
fi
|
||||||
|
rm -r "$name"
|
||||||
|
}
|
||||||
|
|
||||||
|
touch t
|
||||||
|
|
||||||
|
do_test 1 a /bin
|
||||||
|
do_test 2 a/b .
|
||||||
|
do_test 3 a/b ..
|
||||||
|
do_test 4 a/b ../t
|
||||||
|
|
||||||
|
rm -rf "$dir"
|
Loading…
Add table
Add a link
Reference in a new issue