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

path-conversion: Prevent conversion of commandline flags. #11

Merged
merged 1 commit into from
Jun 17, 2015
Merged

path-conversion: Prevent conversion of commandline flags. #11

merged 1 commit into from
Jun 17, 2015

Conversation

nalla
Copy link

@nalla nalla commented Jun 17, 2015

When calling windows apps from MSYS2, the runtime tries to convert
windows style commandline flags like ´/h´ into C:/path/to/msys2/h.

If the user does not want that behavior the user can now set the the
environment variable WINSTYLE_FLAGS_ONLY when calling that command.

@kblees
Copy link

kblees commented Jun 17, 2015

Why is this needed? Wouldn't it be simpler to stick to the documented path conversion rules [1]? I.e. write //h instead of /h for windows options?

[1] http://www.mingw.org/wiki/Posix_path_conversion

@kusma
Copy link

kusma commented Jun 17, 2015

@kblees I use a lot of bash-scripts with long arguments myself in my daily work-flow, and having an option to disable path-conversions seems pretty convenient. But that's just my two cents.

@dscho
Copy link
Member

dscho commented Jun 17, 2015

Very interesting idea! I'd love to have this feature, with minor changes:

  • could you enhance upon the commit message to include @kusma's use case? (I thought of that use case immediately, but let's just make sure that the commit message really drives home that point even if the reader has not encountered that problem before)
  • I am not at all sure about the name WINSTYLE_FLAGS_ONLY... Maybe something more like KEEP_DOS_FLAGS? Or even simpler: SKIP_P2W?

@nalla
Copy link
Author

nalla commented Jun 17, 2015

Ok wait a minute. I think I know now what was my problem. I was trying to use the following switch msbuild //p:OutputPath=C:/some/path. That got me started with the idea in the first place. Thanks to @kblees hint to the mingw wiki - I got that fixed to msbuild //p:OutputPath=C:\\some\\path

@dscho
Copy link
Member

dscho commented Jun 17, 2015

@nalla while that is correct, it struck my as a major revelation that having the option to switch off the posix2windows mangling wholesale depending on an environment variable is just brilliant.

Now that I think of it: even in our test suite, we could benefit from this: our git blame tests really suffer from p2w mangling and our work-around is uglier than the grandfather of a blobfish. Since we do not need the p2w mangling at all when testing git blame, we could replace this work-around by a simple SKIP_P2W=1; export SKIP_P2W. 👏

Or do I miss anything?

@kblees
Copy link

kblees commented Jun 17, 2015

I am not at all sure about the name WINSTYLE_FLAGS_ONLY... Maybe something more like KEEP_DOS_FLAGS? Or even simpler: SKIP_P2W?

Or we could just add another flag to the MSYS variable, e.g. [no]pathconv?

If we add new environment variables, they should be prefixed with MSYS_ to prevent potential clashes with other applications. And P2W would be meaningless if you don't know the MSYS sources.

@nalla
Copy link
Author

nalla commented Jun 17, 2015

What I can do is change the variable name to MSYS_NO_PATHCONV. As of adding another

flag to the MSYS variable, e.g. [no]pathconv

I must decline due to lack of knowledge and understanding. But If someone else would be willing to go for it - please do so 👍

When calling windows native apps from MSYS2, the runtime tries to convert
commandline arguments by a specific set of rules. See [MinGW wiki]
(http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a bash
script, the user can now set the the environment variable
`MSYS_NO_PATHCONV` when calling native windows commands.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
@dscho
Copy link
Member

dscho commented Jun 17, 2015

Or we could just add another flag to the MSYS variable, e.g. [no]pathconv?

The disadvantage of this is that MSYS is interpreted at msys2-runtime startup time IIRC. With the separate environment variable handling, you should be able to switch it off while running inside a Bash (although I did not test that yet).

@dscho
Copy link
Member

dscho commented Jun 17, 2015

With the separate environment variable handling, you should be able to switch it off while running inside a Bash (although I did not test that yet).

Well, I just tested this. With the following echo-args.c:

#include <stdio.h>

int main(int argc, char **argv)
{
    int i;

    for (i = 0; i < argc; i++)
        fprintf(stderr, "arg %d: '%s'\n", i, argv[i]);

    return 0;
}

and a patched msys-2.0.dll:

$ echo-args /h
arg 0: 'C:\censored\echo-args.exe'
arg 1: 'H:/'

$ MSYS_NO_PATHCONV=1 echo-args /h
arg 0: 'C:\censored\echo-args.exe'
arg 1: '/h'

Sweet!!!

dscho added a commit that referenced this pull request Jun 17, 2015
path-conversion: Prevent conversion of commandline flags.
@dscho dscho merged commit e80f57c into git-for-windows:develop Jun 17, 2015
@nalla nalla deleted the winstyle-cmdline-flags branch June 18, 2015 06:36
@dscho
Copy link
Member

dscho commented Jun 18, 2015

Sorry that it takes so long to release this... I encountered build problems in 32-bit mode, but I think that I'll resolve them soon.

@dscho
Copy link
Member

dscho commented Jun 18, 2015

Okay, finally resolved and uploaded to the Pacman repository.

@kumarharsh
Copy link

@dscho it seems like setting the MSYS_NO_PATHCONV variable to 0 is also turning off the path conversion. Is this by design?

@nalla
Copy link
Author

nalla commented Aug 26, 2016

@kumarharsh indeed it is. See 3a68b5b#diff-ee01d88e1ff6a07b0dc99ffc52c1e9f6R348 - The logic only checks if the variable has any value.

@kumarharsh
Copy link

OK, thanks. So setting it to $null (PS) or NUL (cmd) is the way to go.

I must really commend you guys for adding this in. It proved to be a lifesaver for me - I was writing a cross-platform Makefile which was running with the MSYS environment (but from Powershell) and I was trying to mount docker directories. It became such a mess that no matter what I tried, either MSYS was mucking up the path, or docker couldn't read it. This was the only reason I was maintaining a fork of the makefile in powershell PS1 scripts. Now, I'm just setting the environment variable when I need it:

Before:

An example of the makefile without this variable (and still didn't work because MSYS was re-translating the windows paths - also I'm relatively new to makefile so this might not be the best way to do it)

uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
_mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
_pwd := $(patsubst %/,%,$(dir $(_mkfile_path)))
ifeq ($(uname_S),Linux)  # Linux
  WORKING_DIR = $(_pwd)
endif
ifneq (,$(findstring MSYS_NT,$(uname_S)))  # Windows
    _drive := $(shell echo $(firstword $(subst :, ,$(_pwd))) | tr A-Z a-z)
    _path := $(subst \\,/,$(lastword $(subst :, ,$(_pwd))))
    WORKING_DIR := /$(_drive)$(subst :,,$(_path))
endif

.PHONY: restoredb
restoredb: ## Restore all data from a sql file to the database
                docker run -u postgres -v $(WORKING_DIR)/dumps/$(DBName)_dump.sql:/tmp/dump.sql --net host --rm postgres:9.5 psql -f /tmp/dump.sql -h localhost -U postgres $(DBName)

And the actual function in Powershell which did work:

function __getPath($path) {
  return [regex]::replace(   # First, convert the drive letter from windows style to unix style, i.e, C:\ to /c/
    $path,
    '([\w]):\\', {
      param($m)
      '/'+$m.Groups[1].Value.toLower()+'/'
    }
  ).replace('\', '/')     # Then, replace the remaining '\' to '/'
}

function make-restore {
  Param(
    [parameter(Mandatory=$true,position=0)]
    [String]
    $app
  )
  $DB_NAME = "pl_$($app)"
  $hostPath = __getPath "$($pwd)/dumps/$($DB_NAME)_dump.sql"

  docker run -u postgres --net host -v "$($hostPath):/tmp/dump.sql" --rm postgres:9.5 psql -h localhost -U postgres -f /tmp/dump.sql $DB_NAME
  echo "Restored database pl_core"
}

After I found this variable

My makefile:

.PHONY: restoredb
restoredb: export MSYS_NO_PATHCONV=1 # stop path conversion for msys in windows
restoredb: ## Restore all data from a sql file to the database
                docker run -u postgres -v `pwd`/dumps/$(DBName)_dump.sql:/tmp/dump.sql --net host --rm postgres:9.5 psql -f /tmp/dump.sql -h localhost -U postgres $(DBName)

dscho pushed a commit to dscho/Cygwin-msys2-fork that referenced this pull request Dec 1, 2023
When calling windows native apps from MSYS2, the runtime tries to convert
commandline arguments by a specific set of rules. See [MinGW wiki]
(https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a bash
script, the user can now set the the environment variable
`MSYS_NO_PATHCONV` when calling native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables; Many users find the simplicity of
`MSYS_NO_PATHCONV` appealing. So maybe MSYS2 wants that feature, too?

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
dscho pushed a commit to dscho/Cygwin-msys2-fork that referenced this pull request Dec 17, 2023
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing. So let's teach MSYS2 proper
this simple trick that still allows using the sophisticated
`MSYS2_*_CONV_EXCL` facilities but also allows a convenient catch-all
"just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
dscho pushed a commit to dscho/Cygwin-msys2-fork that referenced this pull request Dec 17, 2023
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
lazka pushed a commit to msys2/msys2-runtime that referenced this pull request Dec 18, 2023
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to msys2/msys2-runtime that referenced this pull request Feb 1, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to msys2/msys2-runtime that referenced this pull request Feb 1, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to msys2/msys2-runtime that referenced this pull request Feb 11, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to dscho/msys2-runtime that referenced this pull request Feb 25, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to dscho/Cygwin-msys2-fork that referenced this pull request Feb 27, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to msys2/msys2-runtime that referenced this pull request Apr 6, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
lazka pushed a commit to msys2/msys2-runtime that referenced this pull request Aug 25, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho pushed a commit to msys2/msys2-runtime that referenced this pull request Aug 27, 2024
When calling windows native apps from MSYS2, the runtime tries to
convert commandline arguments by a specific set of rules. This idea was
inherited from the MSys/MinGW project (which is now seemingly stale, yet
must be credited with championing this useful feature, see MinGW wiki
https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion).

If the user does not want that behavior on a big scale, e.g. inside a
Bash script, with the changes introduced in this commit, the user can
now set the the environment variable `MSYS_NO_PATHCONV` when calling
native windows commands.

This is a feature that has been introduced in Git for Windows via
git-for-windows/msys2-runtime#11 and it predates
support for the `MSYS2_ENV_CONV_EXCL` and `MSYS2_ARG_CONV_EXCL`
environment variables in the MSYS2 runtime; Many users find the
simplicity of `MSYS_NO_PATHCONV` appealing.

So let's teach MSYS2 proper this simple trick that still allows using
the sophisticated `MSYS2_*_CONV_EXCL` facilities but also offers a
convenient catch-all "just don't convert anything" knob.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
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 this pull request may close these issues.

5 participants