|
1 | 1 | #!/bin/bash
|
2 | 2 | #
|
3 |
| -# Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | +# Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. |
4 | 4 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
5 | 5 | #
|
6 | 6 | # This code is free software; you can redistribute it and/or modify it
|
|
28 | 28 | # available, or extract values automatically from the environment if missing.
|
29 | 29 | # This is robust, but slower.
|
30 | 30 | function setup() {
|
| 31 | + |
| 32 | + # Make regexp tests case insensitive |
| 33 | + shopt -s nocasematch |
| 34 | + # Prohibit msys2 from meddling with paths |
| 35 | + export MSYS2_ARG_CONV_EXCL="*" |
| 36 | + # Make sure WSL gets a copy of the path |
| 37 | + export WSLENV=PATH/l |
| 38 | + |
31 | 39 | while getopts "e:p:r:t:c:qmi" opt; do
|
32 | 40 | case "$opt" in
|
33 | 41 | e) PATHTOOL="$OPTARG" ;;
|
@@ -87,13 +95,6 @@ function setup() {
|
87 | 95 | wintemp_win="$($CMD /q /c echo %TEMP% 2>/dev/null | tr -d \\n\\r)"
|
88 | 96 | WINTEMP="$($PATHTOOL -u "$wintemp_win")"
|
89 | 97 | fi
|
90 |
| - |
91 |
| - # Make regexp tests case insensitive |
92 |
| - shopt -s nocasematch |
93 |
| - # Prohibit msys2 from meddling with paths |
94 |
| - export MSYS2_ARG_CONV_EXCL="*" |
95 |
| - # Make sure WSL gets a copy of the path |
96 |
| - export WSLENV=PATH/l |
97 | 98 | }
|
98 | 99 |
|
99 | 100 | # Cleanup handling
|
@@ -299,6 +300,19 @@ function convert_path() {
|
299 | 300 | if [[ $arg =~ ^([^/]*|-[^:=]*[:=]|.*file://|/[a-zA-Z:]{1,3}:?)($DRIVEPREFIX/)([a-z])(/[^/]+.*$) ]] ; then
|
300 | 301 | prefix="${BASH_REMATCH[1]}"
|
301 | 302 | winpath="${BASH_REMATCH[3]}:${BASH_REMATCH[4]}"
|
| 303 | +
|
| 304 | + # If the thing in its entirety points to an existing path, use that instead of thinking |
| 305 | + # we have a prefix. This can only happen if the top-level directory has a single-letter name. |
| 306 | + if [[ ${#prefix} -eq 2 && "${prefix:0:1}" == "/" ]]; then |
| 307 | + possiblepath="${BASH_REMATCH[1]}/${BASH_REMATCH[3]}${BASH_REMATCH[4]}" |
| 308 | + if [[ -e "$possiblepath" || -e "$(dirname $possiblepath)" || -e "$(echo $possiblepath | cut -d / -f 1-5)" ]] ; then |
| 309 | + prefix= |
| 310 | + drivepart="${possiblepath:1:1}" |
| 311 | + pathpart="${possiblepath:2}" |
| 312 | + winpath="$drivepart:$pathpart" |
| 313 | + fi |
| 314 | + fi |
| 315 | +
|
302 | 316 | # Change slash to backslash (or vice versa if mixed mode)
|
303 | 317 | if [[ $MIXEDMODE != true ]]; then
|
304 | 318 | winpath="${winpath//'/'/'\'}"
|
|
0 commit comments