fix problem on windows with newly rewritten prop_relPathDirToFileAbs_basics
authorJoey Hess <joeyh@joeyh.name>
Fri, 22 Jan 2021 18:21:29 +0000 (14:21 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 22 Jan 2021 18:30:48 +0000 (14:30 -0400)
Seems that dropDrive on windows only drops eg c:/ but not a leading /
while on linux, it does drop a leading / (which is what it considers
to be equivilant to a drive letter. I had been relying on it to drop
both. So need to drop leading directory separators.

Also, if the quickcheck generated input is eg "c:c:c:c:foo",
dropDrive will only drop the first one, leaving a path that's
still not relative. So instead of using dropDrive, just remove the
colons from the path.

Utility/Path/Tests.hs
doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_3_e8432845460fd0598f8fea5d00c70993._comment [new file with mode: 0644]

index c09151e4cd707429ed5d00fd661a43957fa4980c..94deff936764f4ff6905392ece8893a9260e6208 100644 (file)
@@ -1,7 +1,7 @@
 {- Tests for Utility.Path. Split into a separate module to avoid it needing
  - QuickCheck.
  -
- - Copyright 2010-2020 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2021 Joey Hess <id@joeyh.name>
  -
  - License: BSD-2-clause
  -}
@@ -20,6 +20,7 @@ import System.FilePath.ByteString
 import qualified Data.ByteString as B
 import Data.List
 import Data.Maybe
+import Data.Char
 import Control.Applicative
 import Prelude
 
@@ -42,10 +43,14 @@ prop_relPathDirToFileAbs_basics pt = and
        , relPathDirToFileAbs p p == ""
        ]
   where
-       -- Make the input an absolute path, since relPathDirToFileAbs
-       -- needs absolute paths.
-       p = pathSeparator `B.cons` dropDrive
-               (toRawFilePath (fromTestableFilePath pt))
+       -- relPathDirToFileAbs needs absolute paths, so make the path
+       -- absolute by adding a path separator to the front.
+       p = pathSeparator `B.cons` relf
+       -- Make the input a relative path. On windows, make sure it does
+       -- not contain anything that looks like a drive letter.
+       relf = B.filter (not . skipchar) $ B.dropWhile isPathSeparator $
+               toRawFilePath (fromTestableFilePath pt)
+       skipchar b = b == (fromIntegral (ord ':'))
 
 prop_relPathDirToFileAbs_regressionTest :: Bool
 prop_relPathDirToFileAbs_regressionTest = same_dir_shortcurcuits_at_difference
diff --git a/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_3_e8432845460fd0598f8fea5d00c70993._comment b/doc/bugs/prop__95__relPathDirToFileAbs__95__basics_fail_on_crippled___126__/comment_3_e8432845460fd0598f8fea5d00c70993._comment
new file mode 100644 (file)
index 0000000..7f8b0c9
--- /dev/null
@@ -0,0 +1,9 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 3"""
+ date="2021-01-22T18:06:21Z"
+ content="""
+Please do not followup to closed bug reports with new problems.
+
+I've fixed this problem.
+"""]]