Skip to content

Commit

Permalink
Add warning for broken symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
wjandrea committed Apr 12, 2023
1 parent 50f81e4 commit 0a8d3cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Options:
Info provided per symlink:
- target, recursively
- (if relative: canonical path)
- (if broken: warning)
Exit Status:
3 - Invalid options
Expand Down
10 changes: 9 additions & 1 deletion src/symlink-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Options:
Info provided per symlink:
- target, recursively
- (if relative: canonical path)
- (if broken: warning)
Exit Status:
3 - Invalid options
Expand Down Expand Up @@ -58,7 +59,7 @@ while getopts :hv OPT; do
exit 0
;;
v)
echo "symlink-info 0.2.2"
echo "symlink-info 0.3.0"
exit 0
;;
*)
Expand Down Expand Up @@ -111,6 +112,13 @@ for path; do
_indent 1
printf 'canonical path: %s\n' "$path_canonical"
fi

if [[ ! -e $path_canonical ]]; then
printf >&2 "%s: Warning: Broken symlink. Target does not exist: %s\n" \
"$basename" \
"$path_canonical"
exit=1
fi
done

exit $exit

0 comments on commit 0a8d3cd

Please sign in to comment.