fix test suite failure on windows
authorJoey Hess <joeyh@joeyh.name>
Wed, 1 Sep 2021 15:32:25 +0000 (11:32 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 1 Sep 2021 15:32:25 +0000 (11:32 -0400)
This was maybe a real bug too, although I don't know what circumstances
it would be a problem. See comment for analysis of this windows drive
letter wackyness issue.

Sponsored-by: Brock Spratlen on Patreon
Utility/Path.hs
doc/bugs/test_prop__95__relPathDirToFileAbs__95__basics_fails_now__38__thn.mdwn
doc/bugs/test_prop__95__relPathDirToFileAbs__95__basics_fails_now__38__thn/comment_1_7becd972ce41d14ace89a9bc1302abba._comment [new file with mode: 0644]

index cfda748b9f7f04c99808bbd4ebaf4400f05dc24e..8c6aa7f704fab3b23310f68e6e39453e2f2cfdbc 100644 (file)
@@ -187,7 +187,13 @@ relPathDirToFileAbs from to
        dotdots = replicate (length pfrom - numcommon) ".."
        numcommon = length common
 #ifdef mingw32_HOST_OS
-       normdrive = map toLower . takeWhile (/= ':') . fromRawFilePath . takeDrive
+       normdrive = map toLower
+               -- Get just the drive letter, removing any leading
+               -- path separator, which takeDrive leaves on the drive
+               -- letter.
+               . dropWhileEnd (isPathSeparator . fromIntegral . ord)
+               . fromRawFilePath 
+               . takeDrive
 #endif
 
 {- Checks if a command is available in PATH.
index 63151051cd668a8df7dbab03902ffdae19b48da9..f65e66893ac780ef3e0ffc1778f7964caeba9738 100644 (file)
@@ -49,3 +49,5 @@ Windows version 21H1 (build 19043.1165), 64 bit.
 Git Annex is great. It works with multi-gigabyte backup files (largest around 180GB) via the BLAKE2B160E backend just dandy :)
 
 [[!meta author=jkniiv]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/test_prop__95__relPathDirToFileAbs__95__basics_fails_now__38__thn/comment_1_7becd972ce41d14ace89a9bc1302abba._comment b/doc/bugs/test_prop__95__relPathDirToFileAbs__95__basics_fails_now__38__thn/comment_1_7becd972ce41d14ace89a9bc1302abba._comment
new file mode 100644 (file)
index 0000000..f5e468d
--- /dev/null
@@ -0,0 +1,28 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2021-09-01T14:54:56Z"
+ content="""
+Reproduced on Linux using System.FilePath.Windows.
+
+Minimal case is:
+
+       ghci> let p = "\\\\\DLEJ\STXm{u5;4*\EOTKo1"
+       ghci> relPathDirToFileAbs (p </> "bar") p
+       "\\\\\DLEJ\STXm{u5;4*\EOTKo1"
+
+Which should be "bar", but the "normdrive" case in
+relPathDirToFileAbs causes it to not return that.
+
+Ah, that whole value is treated as a "drive letter" due to starting
+with "\\\\" and not containing any path separator.
+
+       ghci> takeDrive p
+       "\\\\\DLEJ\STXm{u5;4*\EOTKo1"
+
+And takeDrive includes the first path separator, which is present in one
+string and not in another. So, it thinks these paths are on
+two different drives, when they are not. And that's the root
+of the problem. normdrive was working around that by taking up until 
+the ':', but there *is* no ':' in this drive letter!
+"""]]