Skip to content

Commit 8460ef8

Browse files
RyanGlScottMistuke
authored andcommitted
Make cygwinMSYSCheck more robust (#186)
We cannot rely on `"-master`" being at the end of the filepath name in `cygwinMSYSCheck` on recent MinTTYs. To accommodate, this patch updates the implementation of `cygwinMSYSCheck` to match what `git-for-windows` does: * Always use `isInfixOf` to check if `"cygwin-"`, `"msys-"`, and "`-pty"` are in the filepath name. * Don't check `"-master"` at all, as this seems to assume a naming convention that could change in the future. Fixes #186.
1 parent cd69b19 commit 8460ef8

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

System/Win32/MinTTY.hsc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import System.Win32.Types
3131
#if MIN_VERSION_base(4,6,0)
3232
import Control.Exception (catch)
3333
#endif
34-
import Data.List (isPrefixOf, isInfixOf, isSuffixOf)
34+
import Data.List (isInfixOf)
3535
import Foreign
3636
import Foreign.C.Types
37-
import System.FilePath (takeFileName)
3837

3938
#if __GLASGOW_HASKELL__ < 711
4039
#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)
@@ -91,11 +90,8 @@ isMinTTYCompat h = do
9190
return False
9291

9392
cygwinMSYSCheck :: String -> Bool
94-
cygwinMSYSCheck fn = ("cygwin-" `isPrefixOf` fn' || "msys-" `isPrefixOf` fn') &&
95-
"-pty" `isInfixOf` fn' &&
96-
"-master" `isSuffixOf` fn'
97-
where
98-
fn' = takeFileName fn
93+
cygwinMSYSCheck fn = ("cygwin-" `isInfixOf` fn || "msys-" `isInfixOf` fn) &&
94+
"-pty" `isInfixOf` fn
9995
-- Note that GetFileInformationByHandleEx might return a filepath like:
10096
--
10197
-- \msys-dd50a72ab4668b33-pty1-to-master
@@ -105,8 +101,16 @@ cygwinMSYSCheck fn = ("cygwin-" `isPrefixOf` fn' || "msys-" `isPrefixOf` fn') &&
105101
-- \Device\NamedPipe\msys-dd50a72ab4668b33-pty1-to-master
106102
--
107103
-- This means we can't rely on "\cygwin-" or "\msys-" being at the very start
108-
-- of the filepath. Therefore, we must take care to first call takeFileName
109-
-- before checking for "cygwin" or "msys" at the start using `isPrefixOf`.
104+
-- of the filepath. As a result, we use `isPrefixOf` to check for "cygwin" and
105+
-- "msys".
106+
--
107+
-- It's unclear if "-master" will always appear in the filepath name. Recent
108+
-- versions of MinTTY have been known to give filepaths like this (#186):
109+
--
110+
-- \msys-dd50a72ab4668b33-pty0-to-master-nat
111+
--
112+
-- Just in case MinTTY ever changes this convention, we don't bother checking
113+
-- for the presence of "-master" in the filepath name at all.
110114

111115
getFileNameByHandle :: HANDLE -> IO String
112116
getFileNameByHandle h = do

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog for [`Win32` package](http://hackage.haskell.org/package/Win32)
22

3+
## next
4+
5+
* Fix a bug in which `System.Win32.MinTTY.isMinTTY` would incorrectly return
6+
`False` on recent versions of MinTTY.
7+
38
## 2.13.0.0 August 2021
49

510
* Fix type of c_SetWindowLongPtr. See #180

0 commit comments

Comments
 (0)