{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
module Data.Validity.Path where
import Data.Validity
import Path
import Path.Internal
import Data.List (isInfixOf, isSuffixOf)
import qualified System.FilePath as FilePath
#if MIN_VERSION_path(0,6,0)
#endif
instance Validity (Path Abs File) where
validate p@(Path fp) =
mconcat
[ declare "The path is absolute." $ FilePath.isAbsolute fp
, declare "The path has no trailing path separator." $
not (FilePath.hasTrailingPathSeparator fp)
, declare "System.FilePath considers the path valid." $
FilePath.isValid fp
, declare "The path does not end in /." $ not ("/." `isSuffixOf` fp)
#if MIN_VERSION_path(0,6,0)
, declare "The path does not equal \".\"" $ fp /= "."
#endif
, declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)
, decorate "The path contains no UTF16 Surrogate codepoints" $ decorateList fp validateCharNotUtf16SurrogateCodePoint
, declare "The path can be identically parsed as an absolute file path." $
parseAbsFile fp == Just p
]
#if MIN_VERSION_path(0,6,0)
#endif
instance Validity (Path Rel File) where
validate p@(Path fp) =
mconcat
[ declare "The path is relative." $ FilePath.isRelative fp
, declare "The path has no trailing path separator." $
not (FilePath.hasTrailingPathSeparator fp)
, declare "System.FilePath considers the path valid." $
FilePath.isValid fp
, declare "The path does not equal \".\"" $ fp /= "."
, declare "The path is not empty" $ not (null fp)
#if MIN_VERSION_path(0,6,0)
, declare "The path does not end in /." $ not ("/." `isSuffixOf` fp)
#endif
, declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)
, decorate "The path contains no UTF16 Surrogate codepoints" $ decorateList fp validateCharNotUtf16SurrogateCodePoint
, declare "The path can be identically parsed as a relative file path." $
parseRelFile fp == Just p
]
instance Validity (Path Abs Dir) where
validate p@(Path fp) =
mconcat
[ declare "The path is absolute." $ FilePath.isAbsolute fp
, declare "The path has a trailing path separator." $
FilePath.hasTrailingPathSeparator fp
, declare "System.FilePath considers the path valid." $
FilePath.isValid fp
, declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)
, decorate "The path contains no UTF16 Surrogate codepoints" $ decorateList fp validateCharNotUtf16SurrogateCodePoint
, declare "The path can be identically parsed as an absolute directory path." $
parseAbsDir fp == Just p
]
#if MIN_VERSION_path(0,6,0)
#else
#endif
instance Validity (Path Rel Dir) where
validate p@(Path fp) =
mconcat
[ declare "The path is relative." $ FilePath.isRelative fp
, declare "The path has a trailing path separator." $
FilePath.hasTrailingPathSeparator fp
, declare "System.FilePath considers the path valid." $
FilePath.isValid fp
, declare "The path is not empty." $ not (null fp)
#if MIN_VERSION_path(0,6,0)
#else
, declare "The path does not equal \".\"" $ fp /= "."
#endif
, declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)
, decorate "The path contains no UTF16 Surrogate codepoints" $ decorateList fp validateCharNotUtf16SurrogateCodePoint
, declare "The path can be identically parsed as a relative directory path." $
parseRelDir fp == Just p
]