more OsPath conversion
Sponsored-by: Leon Schuermann
This commit is contained in:
parent
ee0964e61b
commit
f3539efc16
18 changed files with 156 additions and 153 deletions
|
@ -17,41 +17,39 @@ module Utility.Path.Tests (
|
|||
prop_dirContains_regressionTest,
|
||||
) where
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import Data.Char
|
||||
import Control.Applicative
|
||||
import Prelude
|
||||
|
||||
import Common
|
||||
import Utility.Path
|
||||
import Utility.QuickCheck
|
||||
import qualified Utility.OsString as OS
|
||||
|
||||
prop_upFrom_basics :: TestableFilePath -> Bool
|
||||
prop_upFrom_basics tdir
|
||||
| dir == "/" = p == Nothing
|
||||
| otherwise = p /= Just dir
|
||||
where
|
||||
p = fromRawFilePath <$> upFrom (toRawFilePath dir)
|
||||
p = fromOsPath <$> upFrom (toOsPath dir)
|
||||
dir = fromTestableFilePath tdir
|
||||
|
||||
prop_relPathDirToFileAbs_basics :: TestableFilePath -> Bool
|
||||
prop_relPathDirToFileAbs_basics pt = and
|
||||
[ relPathDirToFileAbs p (p </> "bar") == "bar"
|
||||
, relPathDirToFileAbs (p </> "bar") p == ".."
|
||||
, relPathDirToFileAbs p p == ""
|
||||
[ relPathDirToFileAbs p (p </> literalOsPath "bar") == literalOsPath "bar"
|
||||
, relPathDirToFileAbs (p </> literalOsPath "bar") p == literalOsPath ".."
|
||||
, relPathDirToFileAbs p p == literalOsPath ""
|
||||
]
|
||||
where
|
||||
-- relPathDirToFileAbs needs absolute paths, so make the path
|
||||
-- absolute by adding a path separator to the front.
|
||||
p = pathSeparator `B.cons` relf
|
||||
p = pathSeparator `OS.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.dropWhile isPathSeparator $
|
||||
B.filter (not . skipchar) $
|
||||
toRawFilePath (fromTestableFilePath pt)
|
||||
skipchar b = b == (fromIntegral (ord ':'))
|
||||
relf = OS.dropWhile isPathSeparator $
|
||||
OS.filter (not . skipchar) $
|
||||
toOsPath (fromTestableFilePath pt)
|
||||
skipchar b = b == unsafeFromChar ':'
|
||||
|
||||
prop_relPathDirToFileAbs_regressionTest :: Bool
|
||||
prop_relPathDirToFileAbs_regressionTest = same_dir_shortcurcuits_at_difference
|
||||
|
@ -60,21 +58,25 @@ prop_relPathDirToFileAbs_regressionTest = same_dir_shortcurcuits_at_difference
|
|||
- location, but it's not really the same directory.
|
||||
- Code used to get this wrong. -}
|
||||
same_dir_shortcurcuits_at_difference =
|
||||
relPathDirToFileAbs (joinPath [pathSeparator `B.cons` "tmp", "r", "lll", "xxx", "yyy", "18"])
|
||||
(joinPath [pathSeparator `B.cons` "tmp", "r", ".git", "annex", "objects", "18", "gk", "SHA256-foo", "SHA256-foo"])
|
||||
== joinPath ["..", "..", "..", "..", ".git", "annex", "objects", "18", "gk", "SHA256-foo", "SHA256-foo"]
|
||||
relPathDirToFileAbs (mkp [fromOsPath (pathSeparator `OS.cons` literalOsPath "tmp"), "r", "lll", "xxx", "yyy", "18"])
|
||||
(mkp [fromOsPath (pathSeparator `OS.cons` literalOsPath "tmp"), "r", ".git", "annex", "objects", "18", "gk", "SHA256-foo", "SHA256-foo"])
|
||||
== mkp ["..", "..", "..", "..", ".git", "annex", "objects", "18", "gk", "SHA256-foo", "SHA256-foo"]
|
||||
where
|
||||
mkp = joinPath . map literalOsPath
|
||||
|
||||
prop_dirContains_regressionTest :: Bool
|
||||
prop_dirContains_regressionTest = and
|
||||
[ not $ dirContains "." ".."
|
||||
, not $ dirContains ".." "../.."
|
||||
, dirContains "." "foo"
|
||||
, dirContains "." "."
|
||||
, dirContains ".." ".."
|
||||
, dirContains "../.." "../.."
|
||||
, dirContains "." "./foo"
|
||||
, dirContains ".." "../foo"
|
||||
, dirContains "../.." "../foo"
|
||||
, dirContains "../.." "../../foo"
|
||||
, not $ dirContains "../.." "../../.."
|
||||
[ not $ dc "." ".."
|
||||
, not $ dc ".." "../.."
|
||||
, dc "." "foo"
|
||||
, dc "." "."
|
||||
, dc ".." ".."
|
||||
, dc "../.." "../.."
|
||||
, dc "." "./foo"
|
||||
, dc ".." "../foo"
|
||||
, dc "../.." "../foo"
|
||||
, dc "../.." "../../foo"
|
||||
, not $ dc "../.." "../../.."
|
||||
]
|
||||
where
|
||||
dc x y = dirContains (literalOsPath x) (literalOsPath y)
|
||||
|
|
|
@ -14,11 +14,10 @@ module Utility.Path.Windows (
|
|||
|
||||
import Utility.Path
|
||||
import Utility.OsPath
|
||||
import Utility.FileSystemEncoding
|
||||
import Utility.SystemDirectory
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import qualified System.FilePath.Windows.ByteString as P
|
||||
import System.Directory (getCurrentDirectory)
|
||||
|
||||
{- Convert a filepath to use Windows's native namespace.
|
||||
- This avoids filesystem length limits.
|
||||
|
@ -36,8 +35,8 @@ convertToWindowsNativeNamespace f
|
|||
| otherwise = do
|
||||
-- Make absolute because any '.' and '..' in the path
|
||||
-- will not be resolved once it's converted.
|
||||
cwd <- toRawFilePath <$> getCurrentDirectory
|
||||
let p = fromOsPath (simplifyPath (toOsPath (combine cwd f)))
|
||||
cwd <- getCurrentDirectory
|
||||
let p = fromOsPath (simplifyPath (combine cwd (toOsPath f)))
|
||||
-- Normalize slashes.
|
||||
let p' = P.normalise p
|
||||
return (win32_file_namespace <> p')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue