Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 557276 - =net-p2p/retroshare-0.6.0_rc2_pre8551: "\~" in pattern substitution is not portable across bash versions
Summary: =net-p2p/retroshare-0.6.0_rc2_pre8551: "\~" in pattern substitution is not po...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Sergey Popov
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-11 05:53 UTC by dwfreed
Modified: 2015-08-12 10:20 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dwfreed 2015-08-11 05:53:14 UTC
> 2015-08-11 04:13:01 < dwfreed> so I might have found a bug in something
> 2015-08-11 04:13:08 < dwfreed> I haven't quite figured out what yet
> 2015-08-11 04:40:10 < dwfreed> okay, so the package is =net-p2p/retroshare-0.6.0_rc2_pre8551
> 2015-08-11 04:40:33 < dwfreed> with the ebuild in its current state, egencache generates the md5-cache, and puts an escape on the ~ in SRC_URI

This is due to the following line in the ebuild:

MY_PV="${MY_PV/_pre/\~}"

Resulting md5-cache SRC_URI, generated by egencache:

SRC_URI=mirror://sourceforge/retroshare/retroshare_0.6.0.RC2\~8551_src.tgz

> 2015-08-11 04:40:53 < dwfreed> however, md5-cache distributed via rsync does not have this escape
> 2015-08-11 04:42:03 < dwfreed> if I run repoman manifest, it tries to download SRC_URI with the escape
> 2015-08-11 04:42:10 < dwfreed> >>> Downloading 'http://gentoo.mirrors.tds.net/gentoo/distfiles/retroshare_0.6.0.RC2\~8551_src.tgz'
> 2015-08-11 04:42:24 < dwfreed> since that file doesn't exist, it 404s
> 2015-08-11 04:43:30 < dwfreed> if I try to generate the manifest myself using the portage API, it complains that DISTDIR/retroshare_0.6.0.RC2\~8551_src.tgz is missing, because retroshare_0.6.0.RC2\~8551_src.tgz is not an existing DIST entry in the thin Manifest
> 2015-08-11 04:44:31 < dwfreed> if I fix the ebuild to not escape the ~ and re-run egencache, I get the correct SRC_URI in md5-cache

Fixed ebuild line:

MY_PV="${MY_PV/_pre/~}"

Resulting md5-cache SRC_URI, again generated by egencache:

SRC_URI=mirror://sourceforge/retroshare/retroshare_0.6.0.RC2~8551_src.tgz

> 2015-08-11 04:46:28 < dwfreed> then running repoman manifest does nothing, because it already has an assumed-correct DIST entry
> 2015-08-11 04:47:46 < dwfreed> and the generating the manifest myself works correctly too
> 2015-08-11 04:48:03 < dwfreed> so the question is, whose bug is it?

Playing around in straight bash, I get this:

# PN=retroshare
# PV=0.6.0_rc2_pre8551
# MY_PV="${PV/_rc/.RC}"
# MY_PV="${MY_PV/_pre/\~}"
# SRC_URI="mirror://sourceforge/retroshare/${PN}_${MY_PV}_src.tgz"
# echo $SRC_URI
mirror://sourceforge/retroshare/retroshare_0.6.0.RC2\~8551_src.tgz

# PN=retroshare
# PV=0.6.0_rc2_pre8551
# MY_PV="${PV/_rc/.RC}"
# MY_PV="${MY_PV/_pre/~}" # difference being not escaping the ~
# SRC_URI="mirror://sourceforge/retroshare/${PN}_${MY_PV}_src.tgz"
# echo $SRC_URI
mirror://sourceforge/retroshare/retroshare_0.6.0.RC2~8551_src.tgz

So perhaps egencache is doing the right thing, and whatever generates the rsync md5-cache needs fixing?  And if so, somebody should fix the ebuild (cc pinkbyte, the maintainer).
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-08-11 06:03:50 UTC
Long story short, this is behavior dependent on bash version. dwfreed figured out 4.3+ gives '~' while <=4.2 gives '\~'. You can't use that syntax.
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-08-11 06:09:43 UTC
And just to be clear, you can't use '~' directly either, since bash 4.3+ will expand that to home directory.

Cheap workarounds:

1. prepend more characters before '~' -- can't do here since they vary,

2. put '~' in separate variable, i.e.:

  tilda='~'
  MY_PV=${PV/_pre/${tilda}}

3. use versionator.eclass?
Comment 3 dwfreed 2015-08-11 06:18:56 UTC
@QA: Should we see if it is feasible to put a check in repoman to identify this kind of poorly defined behavior and warn/error as a result?
Comment 4 Tim Harder gentoo-dev 2015-08-11 06:26:33 UTC
4. MY_PV="${MY_PV/_pre/\\~}"

That appears to work as well for bash-4.2_p53 and 4.3_p39. Probably bash-4.3 cleaned up some operation precedence issues is my guess.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-08-11 06:32:15 UTC
(In reply to Tim Harder from comment #4)
> 4. MY_PV="${MY_PV/_pre/\\~}"
> 
> That appears to work as well for bash-4.2_p53 and 4.3_p39. Probably bash-4.3
> cleaned up some operation precedence issues is my guess.

That doesn't work with bash-3.2.
Comment 6 dwfreed 2015-08-11 06:36:34 UTC
(In reply to Michał Górny from comment #5)
> (In reply to Tim Harder from comment #4)
> > 4. MY_PV="${MY_PV/_pre/\\~}"
> > 
> > That appears to work as well for bash-4.2_p53 and 4.3_p39. Probably bash-4.3
> > cleaned up some operation precedence issues is my guess.
> 
> That doesn't work with bash-3.2.

Nor is it produce the desired result.  The desired result is a SRC_URI without any escapes in it. (radhermit realized this after discussion on IRC)
Comment 7 Ulrich Müller gentoo-dev 2015-08-11 07:05:51 UTC
Sometimes "ANSI-C quoting" comes in handy:

MY_PV="${MY_PV/_pre/$'\x7e'}"

will work with bash 3.2, 4.2, and 4.3.
Comment 8 Sergey Popov gentoo-dev 2015-08-12 10:20:55 UTC
commit c31708b96ab45da8c17fd8dfc546082f13bbba05
Author: Sergey Popov <pinkbyte@gentoo.org>
Date:   Wed Aug 12 13:15:35 2015 +0300

    net-p2p/retroshare: fix MY_PV, which is non-portable across bash versions wrt bug #557276

    Reported-by: dwfreed <dwfreed AT mtu.edu>
    Suggested-by: Ulrich Müller <ulm AT gentoo.org>
    Package-Manager: portage-2.2.20


Thanks for all suggestions, i was not aware about this