Skip to content
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
8 changes: 4 additions & 4 deletions src/downgrade
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ filter_packages() {
matches_name_version_filter() {
local pkg=$1 name=$2 operator=$3 search_version=$4 pkg_version version_regex

if [[ -z "$operator" ]] || [[ -z "$version" ]]; then
if [[ -z "$operator" ]] || [[ -z "$search_version" ]]; then
Comment thread
pbrisbin marked this conversation as resolved.
return 0
fi

# version: 2025.11.12.r15.g0eed3fe
version_regex="[a-zA-Z0-9.]+"
version_regex="[a-zA-Z0-9._]+"
hash_or_minor="([0-9]+|[a-z0-9]{6,})"
pkg_version=$(sed -r "s/.*$name-($version_regex)(-$hash_or_minor)?-(any|$DOWNGRADE_ARCH)\\.(git)?pkg\\.tar\\.(gz|xz|zst)/\1\2/g" <<<"$pkg")
cmp=$(vercmp "$pkg_version" "$search_version")
Expand Down Expand Up @@ -249,7 +249,7 @@ search_cache() {
local name=$1 pkgfile_re index

# version: 2025.11.12.r15.g0eed3fe
version_regex="[a-zA-Z0-9.]+"
version_regex="[a-zA-Z0-9._]+"
hash_or_minor="([0-9]+|[a-z0-9]{6,})"
pkgfile_re="$name-($version_regex)(-$hash_or_minor)?-(any|$DOWNGRADE_ARCH)\\.pkg\\.tar\\.(gz|xz|zst)"

Expand Down Expand Up @@ -569,7 +569,7 @@ build_pkg() {
local item="$1" path commit_hash build_failed versionreg hashreg gitpkgreg
if [[ "$item" =~ .*gitpkg.tar.gz ]]; then
# version: 2025.11.12.r15.g0eed3fe
versionreg="([a-zA-Z0-9]+\.?)*"
versionreg="([a-zA-Z0-9_]+\.?)*"
hashreg='[a-z0-9]{6,}'
#hash_or_minor="-([0-9]+|[a-z0-9]{6,})" # leaving this as a note, only hash should appear tho
gitpkgreg="(.*)-$versionreg-($hashreg)-(any|$DOWNGRADE_ARCH).gitpkg.tar.gz"
Expand Down
26 changes: 26 additions & 0 deletions test/build_pkg/underscore_version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$ source "$TESTDIR/../helper.sh"
> mkdir -p "$TMP/build_test"
> cd "$TMP/build_test"
> touch PKGBUILD

Mock git, makepkg and su
$ su() {
> local cmd
> while [[ $# -gt 0 ]]; do
> if [[ "$1" == "-c" ]]; then cmd="$2"; break; fi
> shift
> done
> case "$cmd" in
> *"makepkg -fs"*) touch "$TMP/build_test/pkg-1.2_3-1-any.pkg.tar.gz"; return 0 ;;
> git*) return 0 ;;
> "makepkg --packagelist") echo "$TMP/build_test/pkg-1.2_3-1-any.pkg.tar.gz" ;;
> esac
> }
> stat() { echo "testuser"; }
> export -f su stat

It builds package with underscore in version
$ item="$TMP/build_test/pkg-1.2_3-abcdef-any.gitpkg.tar.gz"
> build_pkg "$item"
> cat new_to_install.downgrade | tr '\0' '\n'
/tmp/*/build_test/pkg-1.2_3-1-any.pkg.tar.gz (glob)
21 changes: 21 additions & 0 deletions test/main/matches_name_version_filter.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$ source "$TESTDIR/../helper.sh"

It matches standard version
$ matches_name_version_filter "pkg-1.0.0-1-any.pkg.tar.gz" "pkg" "=" "1.0.0" && echo "match" || echo "no match"
match

It matches version with underscore
$ matches_name_version_filter "pkg-1.2_3-1-any.pkg.tar.gz" "pkg" "=" "1.2_3" && echo "match" || echo "no match"
match

It does not match different version with underscore
$ matches_name_version_filter "pkg-1.2_3-1-any.pkg.tar.gz" "pkg" "=" "1.2_4" && echo "match" || echo "no match"
no match

It handles operators with underscore versions (>=)
$ matches_name_version_filter "pkg-1.2_5-1-any.pkg.tar.gz" "pkg" ">=" "1.2_3" && echo "match" || echo "no match"
match

It handles operators with underscore versions (<)
$ matches_name_version_filter "pkg-1.2_3-1-any.pkg.tar.gz" "pkg" "<" "1.2_5" && echo "match" || echo "no match"
match
8 changes: 8 additions & 0 deletions test/search_cache/specific-version.t
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ With a version string included
> DOWNGRADE_FROM_CACHE=1 search_cache 'foo' | filter_packages 'foo' '<' '2.0-1' | sort
/tmp/*/foo-1.0-1-any.pkg.tar.gz (glob)
/tmp/*/foo-1.1-1-any.pkg.tar.gz (glob)

It finds packages with underscores in version
$ cache=$(mktemp -d)
> touch "$cache/pkg-1.2_3-1-any.pkg.tar.gz"
> touch "$cache/pkg-1.2-1-any.pkg.tar.gz"
> write_pacman_conf "[options]" "CacheDir = $cache/"
> DOWNGRADE_FROM_CACHE=1 search_cache 'pkg' | filter_packages 'pkg' '=' '1.2_3-1' | sort
/tmp/*/pkg-1.2_3-1-any.pkg.tar.gz (glob)