Project

General

Profile

Bug #2628

GMXRC removes trailing colon from existing MANPATH

Added by Peter Kroon over 2 years ago. Updated 3 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Affected version - extra info:
Affected version:
Difficulty:
uncategorized
Close

Description

Hi all,

I also posted this to the gmx userlist some time ago, and was told to make an issue here. Here's the description of the problem:

I noticed that sourcing GMXRC removes any trailing colons from a set
MANPATH environment variable. This colon is syntactically significant,
and removing it causes `mandb` to ignore /etc/manpath.config instead of
appending that file:

unset MANPATH
export MANPATH=/opt/puppetlabs/puppet/share/man:
  1. Note the trailing colon
    echo $MANPATH

/opt/puppetlabs/puppet/share/man:

mandb

mandb: warning: $MANPATH set, appending /etc/manpath.config
...

source /usr/local/gromacs-2018.1/bin/GMXRC
  1. No more trailing colon
    echo $MANPATH
    /usr/local/gromacs-2018.1/share/man:/opt/puppetlabs/puppet/share/man

mandb: warning: $MANPATH set, ignoring /etc/manpath.config
...

Associated revisions

Revision 51b2fdb3 (diff)
Added by Andrey Alekseenko 3 months ago

Rework handling of PATH-like variables in GMXRC.bash/zsh

Old version was not robust to various kinds of trailing colons, as
exerienced in, e.g., #3219.

To make it all safer, a single function, that removes the
old path and adds the new one to the beginning, is introduced.

Tested with:
- GNU bash 4.4.20
- GNU bash 5.0.17
- zsh 5.8
- dash 0.5.8

```
$ replace_in_path ":" "/new" "/old"
/new:
$ replace_in_path "" "/new" "/old"
/new
$ replace_in_path "/old" "/new" "/old"
/new
$ replace_in_path "/old:" "/new" "/old"
/new:
$ replace_in_path "/old:/other" "/new" "/old"
/new:/other
$ replace_in_path ":/other" "/new" "/old"
/new::/other
$ replace_in_path "/other:" "/new" "/old"
/new:/other:
$ replace_in_path "/other:/old" "/new" "/old"
/new:/other
```

Full test:

```
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:

$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:
```

Closes #2628, #3219

Revision 7f00d40f (diff)
Added by Andrey Alekseenko 3 months ago

Rework handling of PATH-like variables in GMXRC.bash/zsh

Old version was not robust to various kinds of trailing colons, as
experienced in, e.g., #3219.

To make it all safer, a single function, that removes the
old path and adds the new one to the beginning, is introduced.

Tested with:
- GNU bash 4.4.20
- GNU bash 5.0.17
- zsh 5.8
- dash 0.5.8

```
$ replace_in_path ":" "/new" "/old"
/new:
$ replace_in_path "" "/new" "/old"
/new
$ replace_in_path "/old" "/new" "/old"
/new
$ replace_in_path "/old:" "/new" "/old"
/new:
$ replace_in_path "/old:/other" "/new" "/old"
/new:/other
$ replace_in_path ":/other" "/new" "/old"
/new::/other
$ replace_in_path "/other:" "/new" "/old"
/new:/other:
$ replace_in_path "/other:/old" "/new" "/old"
/new:/other
```

Full test:

```
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:

$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:
```

Closes #2628, #3219

History

#1 Updated by Gerrit Code Review Bot over 2 years ago

Gerrit received a related patchset '1' for Issue #2628.
Uploader: Paul Bauer ()
Change-Id: gromacs~master~I1438bcb6e5f3acfcc72ef5675f37c0b2fe2ec8d6
Gerrit URL: https://gerrit.gromacs.org/8260

#2 Updated by Paul Bauer over 2 years ago

  • Status changed from New to Fix uploaded

#3 Updated by Anonymous 3 months ago

  • Status changed from Fix uploaded to Resolved

#4 Updated by Anonymous 3 months ago

Also available in: Atom PDF