Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored link checks #2204

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/linkcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ w_download() {
urlkey="$(echo "${url}" | tr / _)"
echo "${url}" > "${datadir}/${urlkey}.url"
}
# shellcheck disable=SC2317
w_download_to() {
shift
w_download "$@"
}

# Extract list of URLs from winetricks
extract_all() {
Expand All @@ -57,7 +62,11 @@ extract_all() {

# https://github.com/koalaman/shellcheck/issues/861
# shellcheck disable=SC1003
grep '^ *w_download ' "${shwinetricks}" | grep -E 'ftp|http' | grep -v "w_linkcheck_ignore=1" | sed 's/^ *//' | tr -d '\\' > url-script-fragment.tmp
grep -E '^[^#]*w_download(_to)? .*(http|ftp)s?://' "${shwinetricks}" \
| grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \
| sed 's/^.*w_download/w_download/' \
| sed -E "s/\\$/%24/g" \
| tr -d '\\' > url-script-fragment.tmp

# shellcheck disable=SC1091
. ./url-script-fragment.tmp
Expand Down
18 changes: 16 additions & 2 deletions tests/shell-checks
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,22 @@ test_shellcheck() {
test_linkcheck() {
# Check for uses of variables in w_download when w_linkcheck_ignore isn't set
# Using w_download https://example.com/${file1} breaks src/linkcheck.sh
# FIXME: technically '$' is valid in a URL, if there's actually a URL using it this will need a tweak
if grep "^ *w_download " src/winetricks | grep -E "ftp|http" | grep -v "w_linkcheck_ignore=1" | sed "s/^ *//" | tr -d "\\\\" | grep "\\$"; then
# Escaped '$', as in '\$' are allowed

test_func() {
# No comment, only with protocol, skip flagged as ignored, remove indention
# and flags, fix double space, get n-th arg, find vars '$' and ignore '\$'.
func_name=${1}
url_arg=${2}
grep -E '^[^#]*'"${func_name}"' .*(http|ftp)s?://' "src/winetricks" \
| grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \
| sed 's/^.*'"${func_name}"'/'"${func_name}"'/' \
| tr -s " " \
| cut -d " " -f "${url_arg}" \
| grep -E "([^\\\\\]+\\$)"
}

if ( test_func "w_download_to" 3 ) || ( test_func "w_download" 2 ); then
w_die "Do not use variables in these URLs, it breaks src/linkcheck.sh"
else
echo "linkcheck checks passed"
Expand Down