Safe Haskell | None |
---|---|
Language | GHC2021 |
FileSystem.OsPath
Description
Provides utilities for working with OsPath
.
Since: 0.1
Synopsis
- type OsPath = OsString
- encode :: FilePath -> Either EncodingException OsPath
- encodeLenient :: FilePath -> OsPath
- encodeThrowM :: (HasCallStack, MonadThrow m) => FilePath -> m OsPath
- encodeFail :: (HasCallStack, MonadFail m) => FilePath -> m OsPath
- unsafeEncode :: HasCallStack => FilePath -> OsPath
- osp :: QuasiQuoter
- ospPathSep :: QuasiQuoter
- encodeValid :: FilePath -> Either EncodingException OsPath
- encodeValidLenient :: FilePath -> OsPath
- encodeValidThrowM :: (HasCallStack, MonadThrow m) => FilePath -> m OsPath
- encodeValidFail :: (HasCallStack, MonadFail m) => FilePath -> m OsPath
- unsafeEncodeValid :: HasCallStack => FilePath -> OsPath
- decode :: OsPath -> Either EncodingException FilePath
- decodeLenient :: OsPath -> FilePath
- decodeDisplayEx :: OsPath -> String
- decodeShow :: OsPath -> String
- decodeThrowM :: (HasCallStack, MonadThrow m) => OsPath -> m FilePath
- decodeFail :: (HasCallStack, MonadFail m) => OsPath -> m FilePath
- unsafeDecode :: HasCallStack => OsPath -> FilePath
- toOsString :: OsPath -> OsString
- fromOsString :: OsString -> Either EncodingException OsPath
- fromOsStringThrowM :: (HasCallStack, MonadThrow m) => OsString -> m OsPath
- fromOsStringFail :: (HasCallStack, MonadFail m) => OsString -> m OsPath
- unsafeFromOsString :: HasCallStack => OsString -> OsPath
- reallyUnsafeFromOsString :: OsString -> OsPath
- (</>) :: OsPath -> OsPath -> OsPath
- (<.>) :: OsPath -> OsString -> OsPath
- (-<.>) :: OsPath -> OsString -> OsPath
- (</>!) :: HasCallStack => OsPath -> FilePath -> OsPath
- (!</>) :: HasCallStack => FilePath -> OsPath -> OsPath
- combineFilePaths :: FilePath -> FilePath -> FilePath
- data EncodingException = EncodingError String (Maybe Word8)
- toTildeState :: OsPath -> TildeState
- data TildeState
- data OsPathNE
- newtype TildeException = MkTildeException OsPath
Types
Type representing filenames/pathnames.
This type doesn't add any guarantees over OsString
.
Encoding
Total
encode :: FilePath -> Either EncodingException OsPath Source #
Encodes a FilePath
to an OsPath
. This is a pure version of filepath's
encodeUtf
that returns the EncodingException
in the event of an
error.
Since: 0.1
encodeLenient :: FilePath -> OsPath Source #
Partial
encodeThrowM :: (HasCallStack, MonadThrow m) => FilePath -> m OsPath Source #
encode
that throws EncodingException
.
Since: 0.1
encodeFail :: (HasCallStack, MonadFail m) => FilePath -> m OsPath Source #
encodeThrowM
with MonadFail
.
Since: 0.1
unsafeEncode :: HasCallStack => FilePath -> OsPath Source #
Encoding + Validation
Total
osp :: QuasiQuoter #
ospPathSep :: QuasiQuoter Source #
Like osp
, except it runs paths through a "replace function" first.
On unix, replaces \
with /
. On windows, does the opposite.
This is convenient for writing paths in a platform-agnostic way i.e. we are expecting a path
"path/to/foo" -- unix "path\to\foo" -- windows
The normal way to handle this would be to use the combine function (</>)
i.e.
[osp|path|]</>
[osp|to|]</>
[osp|foo|]
This can be quite cumbersome for long paths, so we provide this alternative, allowing:
[ospPathSep|path/to/foo]
Which will automatically convert slashes.
encodeValidLenient :: FilePath -> OsPath Source #
Partial
encodeValidThrowM :: (HasCallStack, MonadThrow m) => FilePath -> m OsPath Source #
encodeValid
that throws EncodingException
.
Since: 0.1
encodeValidFail :: (HasCallStack, MonadFail m) => FilePath -> m OsPath Source #
encodeValid
with MonadFail
.
Since: 0.1
unsafeEncodeValid :: HasCallStack => FilePath -> OsPath Source #
Decoding
Total
decodeLenient :: OsPath -> FilePath Source #
decodeDisplayEx :: OsPath -> String Source #
decodeShow :: OsPath -> String Source #
Partial
decodeThrowM :: (HasCallStack, MonadThrow m) => OsPath -> m FilePath Source #
decode
that throws EncodingException
.
Since: 0.1
decodeFail :: (HasCallStack, MonadFail m) => OsPath -> m FilePath Source #
unsafeDecode :: HasCallStack => OsPath -> FilePath Source #
OsString
toOsString :: OsPath -> OsString Source #
fromOsStringThrowM :: (HasCallStack, MonadThrow m) => OsString -> m OsPath Source #
fromOsString
that throws the EncodingException
.
Since: 0.1
fromOsStringFail :: (HasCallStack, MonadFail m) => OsString -> m OsPath Source #
fromOsString
for MonadFail
.
Since: 0.1
unsafeFromOsString :: HasCallStack => OsString -> OsPath Source #
Functions
(</>) :: OsPath -> OsPath -> OsPath #
Combine two paths with a path separator.
If the second path starts with a path separator or a drive letter, then it returns the second.
The intention is that readFile (dir
will access the same file as
</>
file)setCurrentDirectory dir; readFile file
.
Posix: "/directory" </> "file.ext" == "/directory/file.ext" Windows: "/directory" </> "file.ext" == "/directory\\file.ext" "directory" </> "/file.ext" == "/file.ext" Valid x => (takeDirectory x </> takeFileName x) `equalFilePath` x
Combined:
Posix: "/" </> "test" == "/test" Posix: "home" </> "bob" == "home/bob" Posix: "x:" </> "foo" == "x:/foo" Windows: "C:\\foo" </> "bar" == "C:\\foo\\bar" Windows: "home" </> "bob" == "home\\bob"
Not combined:
Posix: "home" </> "/bob" == "/bob" Windows: "home" </> "C:\\bob" == "C:\\bob"
Not combined (tricky):
On Windows, if a filepath starts with a single slash, it is relative to the
root of the current drive. In [1], this is (confusingly) referred to as an
absolute path.
The current behavior of </>
is to never combine these forms.
Windows: "home" </> "/bob" == "/bob" Windows: "home" </> "\\bob" == "\\bob" Windows: "C:\\home" </> "\\bob" == "\\bob"
On Windows, from [1]: "If a file name begins with only a disk designator
but not the backslash after the colon, it is interpreted as a relative path
to the current directory on the drive with the specified letter."
The current behavior of </>
is to never combine these forms.
Windows: "D:\\foo" </> "C:bar" == "C:bar" Windows: "C:\\foo" </> "C:bar" == "C:bar"
(<.>) :: OsPath -> OsString -> OsPath #
Add an extension, even if there is already one there, equivalent to addExtension
.
"/directory/path" <.> "ext" == "/directory/path.ext" "/directory/path" <.> ".ext" == "/directory/path.ext"
(-<.>) :: OsPath -> OsString -> OsPath #
Remove the current extension and add another, equivalent to replaceExtension
.
"/directory/path.txt" -<.> "ext" == "/directory/path.ext" "/directory/path.txt" -<.> ".ext" == "/directory/path.ext" "foo.o" -<.> "c" == "foo.c"
Legacy
Errors
data EncodingException #
Constructors
EncodingError String (Maybe Word8) | Could not decode a byte sequence because it was invalid under the given encoding, or ran out of input in mid-decode. |
Instances
NFData EncodingException | |
Defined in System.OsString.Encoding.Internal Methods rnf :: EncodingException -> () # | |
Exception EncodingException | |
Defined in System.OsString.Encoding.Internal Methods toException :: EncodingException -> SomeException # fromException :: SomeException -> Maybe EncodingException # | |
Show EncodingException | |
Defined in System.OsString.Encoding.Internal Methods showsPrec :: Int -> EncodingException -> ShowS # show :: EncodingException -> String # showList :: [EncodingException] -> ShowS # | |
Eq EncodingException | |
Defined in System.OsString.Encoding.Internal Methods (==) :: EncodingException -> EncodingException -> Bool # (/=) :: EncodingException -> EncodingException -> Bool # |
Tildes
toTildeState :: OsPath -> TildeState Source #
Retrieves the path's "tilde state".
Since: 0.1
data TildeState Source #
Represents the "tilde state" for a given path.
Constructors
TildeStateNone OsPath | The path contains no tildes. |
TildeStatePrefix OsPathNE | The path contained a "tilde prefix" e.g. |
TildeStateNonPrefix OsPath | The path contained a non-prefix tilde. |
Instances
Sum type representing a possible empty OsPath.
Since: 0.1
Constructors
OsPathEmpty | OsPath is empty. Since: 0.1 |
OsPathNonEmpty OsPath | OsPath is non-empty. Since: 0.1 |
Instances
NFData OsPathNE Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath | |||||
Generic OsPathNE Source # | |||||
Defined in FileSystem.OsPath Associated Types
| |||||
Show OsPathNE Source # | Since: 0.1 | ||||
Eq OsPathNE Source # | Since: 0.1 | ||||
type Rep OsPathNE Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath type Rep OsPathNE = D1 ('MetaData "OsPathNE" "FileSystem.OsPath" "fs-utils-0.1-inplace" 'False) (C1 ('MetaCons "OsPathEmpty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OsPathNonEmpty" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsPath))) |
newtype TildeException Source #
Exception for a path containing a tilde.
Constructors
MkTildeException OsPath |
Instances
NFData TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath Methods rnf :: TildeException -> () # | |||||
Exception TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath Methods toException :: TildeException -> SomeException # fromException :: SomeException -> Maybe TildeException # displayException :: TildeException -> String # backtraceDesired :: TildeException -> Bool # | |||||
Generic TildeException Source # | |||||
Defined in FileSystem.OsPath Associated Types
Methods from :: TildeException -> Rep TildeException x # to :: Rep TildeException x -> TildeException # | |||||
Show TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath Methods showsPrec :: Int -> TildeException -> ShowS # show :: TildeException -> String # showList :: [TildeException] -> ShowS # | |||||
Eq TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath Methods (==) :: TildeException -> TildeException -> Bool # (/=) :: TildeException -> TildeException -> Bool # | |||||
type Rep TildeException Source # | Since: 0.1 | ||||
Defined in FileSystem.OsPath type Rep TildeException = D1 ('MetaData "TildeException" "FileSystem.OsPath" "fs-utils-0.1-inplace" 'True) (C1 ('MetaCons "MkTildeException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsPath))) |