Go to file
2016-06-05 16:09:34 +02:00
cbits Merge posix-paths into hpath 2016-05-09 13:31:20 +02:00
src Fix docs and rename RecursiveMode to RecursiveErrorMode 2016-06-05 16:07:46 +02:00
test Rm unused imports 2016-06-05 16:09:34 +02:00
.ghci Basic Path type with parsers and test suite 2015-05-08 13:14:54 +02:00
.gitignore Fork chrisdone's path library 2016-03-08 22:53:42 +01:00
.travis.yml TRAVIS: install missing hscolour 2016-06-01 18:53:54 +02:00
CHANGELOG Release 0.7.5 2016-06-04 00:39:03 +02:00
doctests-hpath.hs TESTS: minor doctest cleanup 2016-05-09 14:17:12 +02:00
doctests-posix.hs Merge posix-paths into hpath 2016-05-09 13:31:20 +02:00
hpath.cabal New API: use CopyMode for overwriting and introduce RecursiveMode 2016-06-05 03:13:33 +02:00
LICENSE Relicense to BSD3 2016-06-04 00:39:03 +02:00
README.md Add examples to README 2016-05-30 16:02:08 +02:00
Setup.hs First commit 2015-05-07 20:15:42 +02:00
update-gh-pages.sh TRAVIS: fix update-gh-pages.sh 2016-06-01 18:45:49 +02:00

HPath

Gitter chat Hackage version Build Status

Support for well-typed paths in Haskell. Also provides ByteString based filepath manipulation.

Motivation

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.

Goals

  • 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 Fn for safe filename guarantees and a RelC class
  • allows pattern matching via unidirectional PatternSynonym
  • uses simple doctest for testing
  • allows ~/ as relative path, because on posix level ~ is just a regular filename that does NOT point to $HOME
  • remove TH, it sucks

Differences to 'posix-paths'

  • uses the word8 package for save word8 literals instead of OverloadedStrings
  • hasTrailingPathSeparator and dropTrailingPathSeparator behave in the same way as their System.FilePath counterpart
  • added various functions:
    • equalFilePath
    • getSearchPath
    • hasParentDir
    • hiddenFile
    • isFileName
    • isValid
    • makeRelative
    • makeValid
    • normalise
    • splitSearchPath
    • stripExtension
  • has a custom versions of openFd which 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 cabal repl:

-- 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)