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

give option to disable regex mode #79

Open
ghost opened this issue Dec 1, 2016 · 15 comments · May be fixed by #101
Open

give option to disable regex mode #79

ghost opened this issue Dec 1, 2016 · 15 comments · May be fixed by #101

Comments

@ghost
Copy link

ghost commented Dec 1, 2016

for example, there is a package in [community] called bonnie++:

[root@bdisk ~]# pacman -Si bonnie++ | egrep '^Name'
Name            : bonnie++

(which pacman installs just fine, of course.)

As we know, + is a regex special character that denotes "one or more of the preceding pattern/character/set/etc."

However:

[root@bdisk ~]# apacman -S bonnie++
notice: enabling regex mode (bonnie++)
Package `bonnie++' does not exist.

Single quoting and SINGLE-escaping the +'s do nothing.
DOUBLE-escaping at least allows it to install:

[root@bdisk ~]# apacman -S bonnie\\+\\+
notice: enabling regex mode (bonnie\+\+)
Pacman Targets    (1): bonnie++

resolving dependencies...
looking for conflicting packages...

Package (1)         New Version  Net Change  Download Size

community/bonnie++  1.97-2         0.14 MiB       0.05 MiB

Total Download Size:   0.05 MiB
Total Installed Size:  0.14 MiB

:: Proceed with installation? [Y/n] 
:: Retrieving packages...
 bonnie++-1.97-2-x86_64                                                                                50.9 KiB  1697K/s 00:00 [#############################################################################] 100%
(1/1) checking keys in keyring                                                                                                 [#############################################################################] 100%
(1/1) checking package integrity                                                                                               [#############################################################################] 100%
(1/1) loading package files                                                                                                    [#############################################################################] 100%
(1/1) checking for file conflicts                                                                                              [#############################################################################] 100%
(1/1) checking available disk space                                                                                            [#############################################################################] 100%
:: Processing package changes...
(1/1) installing bonnie++

Perhaps this should be documented in the man page as well?

@oshazard
Copy link
Owner

Yeah, I'm just going to eliminate the regex feature.

The issue is I thought package names in AUR were restricted to [a-z], [0-9], - but apparently +, _ and more are in use.

@ghost
Copy link

ghost commented Mar 3, 2017

Damn, reverting 0e5bc0f isn't a clean fix.

@ghost
Copy link

ghost commented Mar 3, 2017

Same problem just reverting 062812b..0e5bc0f

/usr/bin/apacman: line 1898: syntax error: unexpected end of file

@ghost
Copy link

ghost commented Mar 3, 2017

Checking out v2.9 works fine. (Though that's a huge and ridiculous patch)

@ghost
Copy link

ghost commented Mar 3, 2017

Yay! I still get an error /usr/bin/apacman: line 362: aurpkglist: command not found, but it actually fucking works! When I put aurpkglist() back, it hangs at :: There are 117 packages that provide libc++:, but that was happening on master anyway. Do not recommend. UPDATE: It wasn't aurpkglist()'s fault.

I started from aabec06 and cherry-picked. The result applies to 9c58d5f (which is, as of this moment, current apacman master). This is not a pull request for obvious reason, please do not merge it to master. UPDATE: Now a merge request.

0001-Feature-69-added-testing-hooks-and-WIP-unit-test-wit.patch
0002-Minor-fixes-for-testing-hooks.patch
0003-Fix-52-install-cached-packages-without-Internet-conn.patch
0004-Fix-9-check-umask.patch
0005-Fix-51-install-groups.-Add-more-exit-codes.patch
0006-Fix-70-parse-config-flag-early.-Update-help-and-verb.patch
0007-Ver-3.0-Fix-71-flag-parameter-syntax.-Add-savedir-fl.patch
0008-Improved-exit-codes-see-man-page-and-fix-72.patch
0009-Fixes-for-gendb-testing-exit-code-8.-Update-unit-tes.patch
0010-Fix-75-clean-build-dir.-Also-check-tmpfs-free-space-.patch
0011-Misc.-fixes-and-temp-file-cleanup.patch
0012-Minor-function-cleanup.patch
0013-Use-the-same-behavior-of-pacman-s-progress-bar.patch
0014-Expand-G-to-fetch-old-AUR-versions-pkgname-ver-or-pk.patch
0015-Syntax-changes-from-master-to-make-the-patch-smaller.patch

Result:
Copy of the patch from the 0473e35 ("Remove regex mode"):

diff --git a/apacman b/apacman
index 3a31551..ef504a4 100755
--- a/apacman
+++ b/apacman
@@ -12,8 +12,6 @@ version="3.1"
 # * --savedir <dir>, --savedir=<dir>
 # * Install AUR packages offline
 # * --testing    for unit testing purposes only
-# * Regex matching for searching packages
-# * Regex matching for installing packages
 # * -P           patched AUR passthrough for pkgfile
 # * Save installed AUR package metadata to database
 # * Enabled --progress by default
@@ -352,32 +350,16 @@ getlistpackages() {
   exit $?
 }
 
-# Tests whether package exists on the aur ($1 is name, $2 is dereferenced variable)
+# Tests whether $1 exists on the aur
 existsinaur() {
   chosenpkg=$(echo "$1" | sed 's/\~$//' | awk -F "==" '{print $1}')
-  val="${!2}"
-
-  regexmatch="$(echo $val | tr -dc '0-9a-z-.\n')"
-  if [[ $val != $regexmatch ]]; then
-     matches=$(aurpkglist "$val")
-     selectprovider "$val" $matches
-     if [[ $providepkg ]]; then
-       eval "$2=\"$providepkg\"" 2>/dev/null
-       chosenpkg="$providepkg"
-     fi
-  fi
-
   rpcinfo "$chosenpkg"
   [[ "$(jshon -Qe resultcount -u < "$tmpdir/$chosenpkg.info")" != "0" ]]
 }
 
 # Tests whether $1 exists in pacman
 existsinpacman() {
-  chosenpkg=$1
-  if [[ $regex = 1 ]]; then
-    chosenpkg=$(selectprovider)
-  fi
-
+  chosenpkg="$1"
   $pacmanbin -Si -- "$chosenpkg" &>/dev/null
 }
 
@@ -433,9 +415,7 @@ selectprovider() {
    providepkg="$virtual"
   elif [[ $# -gt 1 ]]; then
     # Multiple providers
-    provmsg="provide"
-    [[ $regex = 1 ]] && provmsg="match" && unset regex
-    echo -e "${COLOR5}:: ${COLOR1}There are $virtnum packages that $provmsg $virtpkg:${ENDCOLOR}"
+    echo -e "${COLOR5}:: ${COLOR1}There are $virtnum packages that provide $virtpkg:${ENDCOLOR}"
     providepkg=$(pickone $virtnum ${virtual[@]})
   fi
 }
@@ -535,7 +515,7 @@ finddeps() {
       fi
       if existsinpacman "$dep"; then
         pacmandeps+=("$dep")
-      elif existsinaur "$dep" "dep"; then
+      elif existsinaur "$dep"; then
         if [[ $aurdeps ]]; then
           aurdeps=("$dep" "${aurdeps[@]}")
         else
@@ -610,14 +590,6 @@ aurbar() {
   printf "%s %3s%%\r" ${endbar} ${perc}
 }
 
-aurpkglist() {
-  if ! [[ -f "$tmpdir/packages.lst" ]]; then
-    curl -Lfs "$PKGURL/packages.gz" | gunzip > "$tmpdir/packages.lst"
-  fi
-
-  grep -E "$1" "$tmpdir/packages.lst" | sort
-}
-
 rpcinfo() {
   if ! [[ -f "$tmpdir/$1.info" ]]; then
     curl -LfGs --data-urlencode "arg=$1" "$RPCURL=info" > "$tmpdir/$1.info"
@@ -693,7 +665,7 @@ aurversionisnewer() {
   package="$1"
   rpcinfo "$package"
   unset aurversion
-  if existsinaur "$package" "package"; then
+  if existsinaur "$package"; then
     aurversion="$(jshon -Q -e results -a -e Version -u < "$tmpdir/$package.info")"
     if [[ "$(LC_ALL=C vercmp "$aurversion" "$2")" -gt 0  ]]; then
       return 0
@@ -1164,7 +1136,7 @@ installhandling() {
       pacmanpackages+=("$package")
     elif ! [[ $auronly ]] && providedinpacman "$package"; then
       pacmanpackages+=("$providepkg")
-    elif ! [[ $noaur ]] && existsinaur "$package" "package"; then
+    elif ! [[ $noaur ]] && existsinaur "$package"; then
       if finddeps "$package"; then
         # here is where dep dupes are created
         aurpackages+=("$package")
@@ -1533,14 +1505,8 @@ fi
 # Install (-S) handling
 if [[ $option = install ]]; then
   for pkg in ${packageargs[@]}; do
-    regexmatch="$(echo $pkg | tr -dc '0-9a-z-.\n')"
     if [[ "$pkg" =~ ^/ ]]; then
       err "${COLOR7}error:${ENDCOLOR} invalid package name $pkg"
-    elif [[ $regex = 1 ]]; then
-      true
-    elif [[ "$pkg" != "$regexmatch" ]]; then
-      regex='1'
-      echo -e "${COLOR6}notice:${ENDCOLOR} enabling regex mode ($pkg)"
     fi
   done
   installhandling "${packageargs[@]}"
@@ -1575,7 +1541,7 @@ if [[ $option = update ]]; then
       if isignored "$pkg"; then
         checkignores+=("${packages[i]}")
         continue
-      elif ! existsinaur "$pkg" "pkg"; then
+      elif ! existsinaur "$pkg"; then
         extinctpkgs+=("${packages[i]}")
         continue
       fi
@@ -1613,7 +1579,7 @@ if [[ $option = update ]]; then
       ver="${packages[i]##* }"
       if isignored "$pkg"; then
         checkignores+=("${packages[i]}")
-      elif ! existsinaur "$pkg" "pkg"; then
+      elif ! existsinaur "$pkg"; then
         extinctpkgs+=("${packages[i]}")
       elif aurversionisnewer "$pkg" "$ver"; then
         newpackages+=("$pkg")
@@ -1655,7 +1621,7 @@ if [[ $option = download ]]; then
   cd "$olddir"
 
   for package in "${packageargs[@]}"; do
-    if ! [[ $noaur ]] && existsinaur "$package" "package"; then
+    if ! [[ $noaur ]] && existsinaur "$package"; then
       pkglist+=("$package")
     elif ! [[ $auronly ]] && existsinpacman "$package"; then
       abslist+=("$package")
@@ -1751,13 +1717,7 @@ if [[ $option = search || $option = searchinstall ]]; then
     wait
     cp "$tmpdir/${packageargs[0]}.search" "$tmpdir/search.results"
     for ((i=1 ; i<${#packageargs[@]} ; i++)); do
-      regexmatch="$(echo ${packageargs[$i]} | tr -dc '0-9A-Za-z-.\n')"
-      if [[ ${packageargs[$i]} != $regexmatch ]]; then
-        echo -e "${COLOR6}notice:${ENDCOLOR} enabling regex mode (${packageargs[$i]})"
-        grep --color=always -E "${packageargs[$i]}" "$tmpdir/search.results" > "$tmpdir/search.results-2"
-      else
-        grep -xFf "$tmpdir/search.results" "$tmpdir/${packageargs[$i]}.search" > "$tmpdir/search.results-2"
-      fi
+      grep -xFf "$tmpdir/search.results" "$tmpdir/${packageargs[$i]}.search" > "$tmpdir/search.results-2"
       mv "$tmpdir/search.results-2" "$tmpdir/search.results"
     done
     sed -i '/^$/d' "$tmpdir/search.results"
@@ -1843,7 +1803,6 @@ if [[ $option = search || $option = searchinstall ]]; then
   # Remove the tmpfiles
   rm -f "$tmpdir/*search" &>/dev/null
   rm -f "$tmpdir/search.result" &>/dev/null
-  rm -f "$tmpdir/packages.lst" &>/dev/null
   exit
 fi
 

@ghost ghost mentioned this issue Mar 3, 2017
@binhex
Copy link

binhex commented May 2, 2017

@oshazard any ideas when the removal of regex mode might be included in a release?.

@ghost
Copy link

ghost commented Jun 18, 2017

Deleted my fork pull request #91 was based on. Posting the patch here because relevant issue.

0001-Remove-regex-mode.patch.txt

@Sekuraz
Copy link

Sekuraz commented Aug 10, 2017

got bitten by this bug, could you please remove the regex feature? @oshazard

@Sekuraz
Copy link

Sekuraz commented Aug 10, 2017

It also prints the selections after selecting one in regex mode:

> sudo apacman -S 'libc\\+\\+'
notice: enabling regex mode (libc\+\+)
:: There are 4 packages that match libc\+\+:

ENTER

> sudo apacman -S 'libc\\+\\+'
notice: enabling regex mode (libc\+\+)
:: There are 4 packages that match libc\+\+:

Package `1) libc++
2) libc++abi
3) libc++experimental
4) libc++-msan

Enter a selection (default=1): libc++' does not exist.

@Greybane
Copy link

Greybane commented Sep 19, 2017

I have the same issue as @Sekuraz.

@walliski
Copy link

I also have the same issue (Discord package depending on libc++, which breaks everything....)

@lectrode
Copy link

FYI:

The name(s) of the package(s) [...] should consist of lowercase alphanumerics and any of the following characters: @ . _ + - (at symbol, dot, underscore, plus, hyphen). Names are not allowed to start with hyphens or dots.

https://wiki.archlinux.org/index.php/PKGBUILD#Package_name

@lectrode
Copy link

lectrode commented Nov 2, 2017

@oshazard At the top of this issue you said you wanted to remove the regex feature completely, but that was nearly a year ago. I hope you'll consider pull #101. Instead of removing regex entirely, it makes minimal changes. Specifically, it adds support for the valid characters listed here, and changes the regex mode to basic instead of extended. IMHO, it's a working compromise; you can still use wildcards, and packages like bonnie++ are supported again. It also addresses a couple other smaller issues. Please let me know if you want anything changed.

For those trying to install libc++:
libc++ seems to have a couple different issues. One is the plus sign used in the name (fixed with the changes I've submitted). The other issue has to do with split packages.

I occasionally use discord. To avoid the libc++ issue while using apacman I'm currently using flatpak to install and update it (not a solution, but it's a workaround for the interim).

sudo apacman -S flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak install -y flathub com.discordapp.Discord

@walliski
Copy link

walliski commented Nov 2, 2017

My workaround was to use another "package manager" for aur packages until all these problems get fixed; regex breaking, not being able to select if a package is provided by multiple ones etc... Apacman is completly useless for me atm :<

@lectrode
Copy link

lectrode commented Nov 2, 2017

Hopefully we can change that :)

I wanted to resolve the smaller issues before tackling some of the unsupported PKGBUILD features.

So far, with the changes I made, the following should be working:

  • installing packages with plus sign in name (ex: sudo apacman -S atari++)
  • regex mode (ex: sudo apacman -S apacm.*)
  • selecting package from choices (ex: sudo apacman -S linux-headers)
  • interaction-less install (confirming replacing an existing package, for example)
    • (ex: yes|sudo apacman -Syu --noedit)

You're welcome to test the updated script from my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants