Loading...

Streamly.Internal.FileSystem.PosixPath

This module implements a PosixPath type representing a file system path for Posix operating systems. The only assumption about the encoding of the path is that it maps the characters / and . to Word8 representing their ASCII values. Operations are provided to encode and decode using UTF-8 encoding.

Type

newtype PosixPath Source #

A type representing file system paths on Posix.

A PosixPath is validated before construction unless unsafe constructors are used to create it. For validations performed by the safe construction methods see the fromChars function.

Note that in some cases the file system may perform unicode normalization on paths (e.g. Apple HFS), it may cause surprising results as the path used by the user may not have the same bytes as later returned by the file system.

Constructors

PosixPath (Array Word8) 
Instances
Instances details
IsPath PosixPath PosixPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath

IsPath PosixPath (Dir PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (File PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (Branch PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Branch (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Branch (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Rooted (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

Conversions

class IsPath a b where Source #

If the type a b is a member of IsPath it means we know how to convert the type b to and from the base type a.

Methods

unsafeFromPath :: a -> b Source #

Like fromPath but does not check the properties of Path. The user is responsible to maintain the invariants enforced by the type b otherwise surprising behavior may result.

This operation provides performance and simplicity when we know that the properties of the path are already verified, for example, when we get the path from the file system or from the OS APIs.

fromPath :: MonadThrow m => a -> m b Source #

Convert a base path type to other forms of well-typed paths. It may fail if the path does not satisfy the properties of the target type.

toPath :: b -> a Source #

Convert a well-typed path to the base path type. Never fails.

Instances
Instances details
IsPath PosixPath PosixPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath

IsPath WindowsPath WindowsPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath

IsPath PosixPath (Dir PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (File PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (Branch PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Branch (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Branch (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Rooted (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath WindowsPath (Dir WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (File WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (Branch WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Branch (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Branch (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Rooted (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

adapt :: (MonadThrow m, IsPath PosixPath a, IsPath PosixPath b) => a -> m b Source #

Convert a path type to another path type. This operation may fail with a PathException when converting a less restrictive path type to a more restrictive one. This can be used to upgrade or downgrade type safety.

Validation

Construction

fromChunk :: (MonadThrow m, IsPath PosixPath a) => Array Word8 -> m a Source #

See fromChars for failure cases.

unsafeFromChunk :: IsPath PosixPath a => Array Word8 -> a Source #

Unsafe: The user is responsible to make sure that the cases mentioned in PosixPath are satisfied.

fromChars :: (MonadThrow m, IsPath PosixPath a) => Stream Identity Char -> m a Source #

Encode a Unicode string to PosixPath using strict UTF-8 encoding. Fails with InvalidPath exception if:

  • the stream is empty, should have at least one char
  • the stream contains null characters
  • the stream contains invalid unicode characters

fromString :: (MonadThrow m, IsPath PosixPath a) => [Char] -> m a Source #

See fromChars.

>>> fromString = Path.fromChars . Stream.fromList

Statically Verified String Literals

Quasiquoters.

path :: QuasiQuoter Source #

Generates a PosixPath type from a quoted literal.

>>> Path.toString ([path|/usr/bin|] :: PosixPath)
"/usr/bin"

Statically Verified Strings

Template Haskell expression splices.

pathE :: String -> Q Exp Source #

Generates a Haskell expression of type PosixPath from a String.

Elimination

toChunk :: IsPath PosixPath a => a -> Array Word8 Source #

Convert the path to an array of bytes.

toChars :: (Monad m, IsPath PosixPath a) => a -> Stream m Char Source #

Decode the path to a stream of Unicode chars using strict UTF-8 decoding.

toChars_ :: (Monad m, IsPath PosixPath a) => a -> Stream m Char Source #

Decode the path to a stream of Unicode chars using lax UTF-8 decoding.

toString :: IsPath PosixPath a => a -> [Char] Source #

Decode the path to a Unicode string using strict UTF-8 decoding.

toString_ :: IsPath PosixPath a => a -> [Char] Source #

Decode the path to a Unicode string using strict UTF-8 decoding.

Separators

dropTrailingSeparators :: PosixPath -> PosixPath Source #

If the path is // the result is /. If it is a// then the result is a.

Tests

isRooted :: PosixPath -> Bool Source #

A path that is attached to a root e.g. "x" or ".x" are rooted paths. "/" is considered an absolute root and "." as a dynamic root. ".." is not considered a root, "..x" or "xy" are not rooted paths.

  • An absolute rooted path: / starting from file system root
  • A dynamic rooted path: ./ relative to current directory

isBranch :: PosixPath -> Bool Source #

A path that is not attached to a root e.g. a/b/c or ../b/c.

>>> isBranch = not . Path.isRooted

Joining

append :: PosixPath -> PosixPath -> PosixPath Source #

Append a PosixPath to another. Fails if the second path refers to a rooted path and not a branch. Use unsafeAppend to avoid failure if you know it is ok to append the path or use the typesafe Streamly.FileSystem.OS_PATH.Seg module.

>>> Path.toString $ Path.append [path|/usr|] [path|bin|]
"/usr/bin"

append' :: PosixPath -> PosixPath -> PosixPath Source #

A stricter version of append which requires the first path to be a directory like path i.e. with a trailing separator.

appendCString :: PosixPath -> CString -> IO PosixPath Source #

Append a separator and a CString to the Array.

TODO: This always appends a separator and does not perform any other checks like append.

appendCString' :: PosixPath -> CString -> IO PosixPath Source #

Append a separator and a CString to the Array.

TODO: This always appends a separator and does not perform any other checks like append.

Splitting

Equality

data EqCfg Source #

Options for path comparison operation. By default path comparison uses a strict criteria for equality. The following options are provided to control the strictness.

Constructors

EqCfg 

Fields