blurstudio / hab

A application environment and launcher
GNU Lesser General Public License v3.0
25 stars 3 forks source link

Cygpath is only required for the PATH variable when using cygwin #42

Closed MHendricks closed 1 year ago

MHendricks commented 1 year ago

Addresses #41 by only calling cygpath when processing the PATH env var.

Checklist

Types of Changes

Proposed Changes

After some more testing I've figured out that we only need to convert to cygpath and use : when modifying the PATH env variable, not any of the other environment variables. https://cygwin.com/cygwin-ug-net/setup-env.html.

If you run this in cygwin

export AB="\\\\example\a\path;c:\temp"
export AB="$AB;c:\other;\\\\server\share"
py -c "import os;print(os.environ['AB'])"

It outputs \\example\a\path;c:\temp;c:\other;\\server\share which is expected.

If you try to do the same for PATH, it does not work as expected

export PATH="$PATH;c:\other;\\\\server\share"
py -c "import os;from pprint import pprint;pprint(os.environ['PATH'].split(';'))"

Outputs:

[...,
 'C:\\Program Files\\Git\\usr\\bin\\core_perl',
 'c',
 'C:\\other',
 '\\server\\share']

'c', is incorrect and could cause issues. If you reset your bash and run this instead, it works as expected:

export PATH="$PATH:/c/other;//server/share"
py -c "import os;from pprint import pprint;pprint(os.environ['PATH'].split(';'))"
[...,
 'C:\\Program Files\\Git\\usr\\bin\\core_perl',
 'C:\\other',
 '\\server\\share']

The previous cygpath commit was applying that fix to all environment variables, but it turns out we only need to apply it to PATH. This MR changes hab to only apply cygpath changes for the PATH environment variable.