Support for well-typed paths in Haskell. Also provides ByteString based filepath manipulation.
The motivation came during development of hsfm which has a pretty strict File type, but lacks a strict Path type, e.g. for user input.
The library that came closest to my needs was path, but the API turned out to be oddly complicated for my use case, so I decided to fork it.
Similarly, posix-paths was exactly what I wanted for the low-level operations, but upstream seems dead, so it is forked as well and merged into this library.
- well-typed paths
- high-level API to file operations like recursive directory copy
- safe filepath manipulation, never using String as filepath, but ByteString
- still allowing sufficient control to interact with the underlying low-level calls
Note: this library was written for posix systems and it will probably not support other systems.
Differences to 'path'
- doesn't attempt to fake IO-related information into the path, so whether a path points to a file or directory is up to your IO-code to decide...
- trailing path separators will be preserved if they exist, no messing with that
- uses safe ByteString for filepaths under the hood instead of unsafe String
- fixes broken dirname
- renames dirname/filename to basename/dirname to match the POSIX shell functions
- introduces a new
Path Fnfor safe filename guarantees and a
- allows pattern matching via unidirectional PatternSynonym
- uses simple doctest for testing
~/as relative path, because on posix level
~is just a regular filename that does NOT point to
- remove TH, it sucks
Differences to 'posix-paths'
- uses the
word8package for save word8 literals instead of
dropTrailingPathSeparatorbehave in the same way as their
- added various functions:
- has a custom versions of
openFdwhich allows more control over the flags than its unix package counterpart
- adds a
getDirectoryContents'version that works on Fd
Examples in ghci
Start ghci via
-- enable OverloadedStrings :set -XOverloadedStrings -- import HPath.IO import HPath.IO -- parse an absolute path abspath <- parseAbs "/home" -- parse a relative path (e.g. user users home directory) relpath <- parseRel "jule" -- concatenate paths let newpath = abspath </> relpath -- get file type getFileType newpath -- return all contents of that directory getDirsFiles newpath -- return all contents of the parent directory getDirsFiles (dirname newpath)
* fix build with ghc-7.6
* raise required bytestring version
* Tighten base bound to prevent building before GHC 7.6 (by George Wilson)
* fix build with ghc-7.8 and 7.10
* don't force "Path Abs" anymore in IO module, abstract more over Path types
* add 'toAbs'
* add 'readFile', 'readFileEOF', 'writeFile' and 'appendFile'
* 'copyDirRecursiveOverwrite', 'copyFileOverwrite', 'easyCopyOverwrite' and 'moveFileOverwrite' have been removed, instead use the versions without the *Overwrite suffix and pass in 'Strict' (for default behavior) or 'Overwrite' as the CopyMode argument
* introduced a new 'RecursiveErrorMode' type to allow controlling recursive behavior of 'copyDirRecursive' (use 'FailEarly' for default behavior)
* 'createRegularFile' and 'createDir' now take FileMode as a parameter (also see 'newFilePerms' and 'newDirPerms')
* various documentation fixes
* improved reliability of tests
* relicense to BSD3
* don't expose HPath.Internal
* fix tests, so they work with the sdist tarball too
* added the following function to HPath.IO: createSymlink
* various cleanups and documentation improvements
* added the following functions to System.Posix.FilePath: splitSearchPath, getSearchPath, stripExtension, makeRelative, makeValid
* use 'sendfile' from 'simple-sendfile' in _copyFile and do read/write as a fallback only
* add isFileName, hasParentDir, hiddenFile to System.Posix.FilePath
* add our own openFd version for more control
* small documentation improvements
* add a getDirectoryContents' version that works on Fd
* lift version constraints in benchmark
* remove fpToString and userStringToFP, use Data.ByteString.UTF8 directly instead
* fixes 'throwDestinationInSource' to be more reliable.
* removes some unused HPathIOException constructors
* consistently provide exception constructor identifiers
* be less harsh when non-supported file types get passed to our functions, possibly ignoring them
* minor cleanups
* Adds our posix-paths fork and a lot of IO operations.
* First version of the fork.
* Fix haddock problem.
* Reject only .. and .
* Use filepath's isValid function for additional sanity checks
* Disable parsing of path consisting only of "."
* Add NFData instance for Path
* Some typo/docs improvements
* Add standard headers to modules
* Added conversion functions.
* Rename parentAbs to simply parent.
* Add dirname.
* Removed Generic instance.
* Implemented stricter parsing, disabling use of "..".
* Made stripDir generic over MonadThrow
* Fix stripDir p p /= Nothing bug.
* Removed unused DeriveGeneric.