Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module implements relative paths within a Tree. All paths are anchored at a certain root (this is usually the Tree root). They are represented by a list of Names (these are just strict bytestrings).
- newtype Name = Name ByteString
- newtype AnchoredPath = AnchoredPath [Name]
- anchoredRoot :: AnchoredPath
- appendPath :: AnchoredPath -> Name -> AnchoredPath
- anchorPath :: FilePath -> AnchoredPath -> FilePath
- isPrefix :: AnchoredPath -> AnchoredPath -> Bool
- parent :: AnchoredPath -> AnchoredPath
- parents :: AnchoredPath -> [AnchoredPath]
- catPaths :: AnchoredPath -> AnchoredPath -> AnchoredPath
- flatten :: AnchoredPath -> ByteString
- makeName :: String -> Name
- appendToName :: AnchoredPath -> String -> AnchoredPath
- floatBS :: ByteString -> AnchoredPath
- floatPath :: FilePath -> AnchoredPath
- replacePrefixPath :: AnchoredPath -> AnchoredPath -> AnchoredPath -> AnchoredPath
Documentation
newtype AnchoredPath Source
This is a type of "sane" file paths. These are always canonic in the sense that there are no stray slashes, no ".." components and similar. They are usually used to refer to a location within a Tree, but a relative filesystem path works just as well. These are either constructed from individual name components (using "appendPath", "catPaths" and "makeName"), or converted from a FilePath ("floatPath" -- but take care when doing that) or .
Eq AnchoredPath | |
Ord AnchoredPath | |
Show AnchoredPath | |
(Functor m, Monad m) => TreeRW (TreeMonad m) | |
(Functor m, Monad m) => TreeRO (TreeMonad m) | |
(Functor m, Monad m) => MonadProgress (TreeMonad m) | |
(Functor m, Monad m) => ApplyMonad (TreeMonad m) Tree | |
type ApplyMonadBase (TreeMonad m) = m |
appendPath :: AnchoredPath -> Name -> AnchoredPath Source
Append an element to the end of a path.
anchorPath :: FilePath -> AnchoredPath -> FilePath Source
isPrefix :: AnchoredPath -> AnchoredPath -> Bool Source
Check whether a path is a prefix of another path.
parent :: AnchoredPath -> AnchoredPath Source
Get parent (path) of a given path. foobarbaz -> foo/bar
parents :: AnchoredPath -> [AnchoredPath] Source
List all parents of a given path. foobarbaz -> [foo, foo/bar]
catPaths :: AnchoredPath -> AnchoredPath -> AnchoredPath Source
Catenate two paths together. Not very safe, but sometimes useful (e.g. when you are representing paths relative to a different point than a Tree root).
flatten :: AnchoredPath -> ByteString Source
appendToName :: AnchoredPath -> String -> AnchoredPath Source
Append a ByteString to the last Name of an AnchoredPath.
Unsafe functions.
floatBS :: ByteString -> AnchoredPath Source
Unsafe. Only ever use on bytestrings that came from flatten on a pre-existing AnchoredPath.
floatPath :: FilePath -> AnchoredPath Source
Take a relative FilePath and turn it into an AnchoredPath. The operation is (relatively) unsafe. Basically, by using floatPath, you are testifying that the argument is a path relative to some common root -- i.e. the root of the associated Tree object. Also, there are certain invariants about AnchoredPath that this function tries hard to preserve, but probably cannot guarantee (i.e. this is a best-effort thing). You should sanitize any FilePaths before you declare them "good" by converting into AnchoredPath (using this function).
replacePrefixPath :: AnchoredPath -> AnchoredPath -> AnchoredPath -> AnchoredPath Source
Take a prefix path, the changed prefix path, and a path to change. Assumes the prefix path is a valid prefix. If prefix is wrong return AnchoredPath [].