-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Support for well-typed paths -- -- Support for well-typed paths, utilizing ByteString under the hood. @package hpath @version 0.7.2 module System.Posix.Directory.Foreign newtype DirType DirType :: Int -> DirType data Flags Flags :: Int -> Flags UnsupportedFlag :: String -> Flags unFlags :: Flags -> Int -- | Returns True if posix-paths was compiled with support for the -- provided flag. (As of this writing, the only flag for which this check -- may be necessary is oCloexec; all other flags will always yield -- True.) isSupported :: Flags -> Bool -- | O_CLOEXEC is not supported on every POSIX platform. Use -- isSupported oCloexec to determine if support for -- O_CLOEXEC was compiled into your version of posix-paths. (If -- not, using oCloexec will throw an exception.) oCloexec :: Flags dtBlk :: DirType oAppend :: Flags dtChr :: DirType pathMax :: Int oAsync :: Flags dtDir :: DirType oCreat :: Flags dtFifo :: DirType unionFlags :: [Flags] -> CInt dtLnk :: DirType oDirectory :: Flags oExcl :: Flags dtReg :: DirType oNoctty :: Flags dtSock :: DirType oNofollow :: Flags dtUnknown :: DirType oNonblock :: Flags oRdonly :: Flags oWronly :: Flags oRdwr :: Flags oSync :: Flags oTrunc :: Flags instance GHC.Show.Show System.Posix.Directory.Foreign.Flags instance GHC.Classes.Eq System.Posix.Directory.Foreign.Flags instance GHC.Show.Show System.Posix.Directory.Foreign.DirType instance GHC.Classes.Eq System.Posix.Directory.Foreign.DirType -- | Provides an alternative for openFd which gives us more control -- on what status flags to pass to the low-level open(2) call, -- in contrast to the unix package. module System.Posix.FD -- | Open and optionally create this file. See Files for information -- on how to use the FileMode type. -- -- Note that passing Just x as the 4th argument triggers the -- oCreat status flag, which must be set when you pass in -- oExcl to the status flags. Also see the manpage for -- open(2). openFd :: RawFilePath -> OpenMode -> [Flags] -> Maybe FileMode -> IO Fd -- | Random and general IO/monad utilities. module HPath.IO.Utils -- | If the value of the first argument is True, then execute the action -- provided in the second argument, otherwise do nothing. whenM :: Monad m => m Bool -> m () -> m () -- | If the value of the first argument is False, then execute the action -- provided in the second argument, otherwise do nothing. unlessM :: Monad m => m Bool -> m () -> m () -- | The equivalent of System.FilePath on raw (byte string) file -- paths. -- -- Not all functions of System.FilePath are implemented yet. Feel -- free to contribute! module System.Posix.FilePath -- | Path separator character pathSeparator :: Word8 -- | Check if a character is the path separator -- --
--   \n ->  (_chr n == '/') == isPathSeparator n
--   
isPathSeparator :: Word8 -> Bool -- | Search path separator searchPathSeparator :: Word8 -- | Check if a character is the search path separator -- --
--   \n -> (_chr n == ':') == isSearchPathSeparator n
--   
isSearchPathSeparator :: Word8 -> Bool -- | File extension separator extSeparator :: Word8 -- | Check if a character is the file extension separator -- --
--   \n -> (_chr n == '.') == isExtSeparator n
--   
isExtSeparator :: Word8 -> Bool -- | Take a ByteString, split it on the searchPathSeparator. Blank -- items are converted to .. -- -- Follows the recommendations in -- http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html -- --
--   >>> splitSearchPath "File1:File2:File3"
--   ["File1","File2","File3"]
--   
--   >>> splitSearchPath "File1::File2:File3"
--   ["File1",".","File2","File3"]
--   
--   >>> splitSearchPath ""
--   ["."]
--   
splitSearchPath :: ByteString -> [RawFilePath] -- | Get a list of RawFilePaths in the $PATH variable. getSearchPath :: IO [RawFilePath] -- | Split a RawFilePath into a path+filename and extension -- --
--   >>> splitExtension "file.exe"
--   ("file",".exe")
--   
--   >>> splitExtension "file"
--   ("file","")
--   
--   >>> splitExtension "/path/file.tar.gz"
--   ("/path/file.tar",".gz")
--   
-- --
--   \path -> uncurry (BS.append) (splitExtension path) == path
--   
splitExtension :: RawFilePath -> (RawFilePath, ByteString) -- | Get the final extension from a RawFilePath -- --
--   >>> takeExtension "file.exe"
--   ".exe"
--   
--   >>> takeExtension "file"
--   ""
--   
--   >>> takeExtension "/path/file.tar.gz"
--   ".gz"
--   
takeExtension :: RawFilePath -> ByteString -- | Change a file's extension -- --
--   \path -> let ext = takeExtension path in replaceExtension path ext == path
--   
replaceExtension :: RawFilePath -> ByteString -> RawFilePath -- | Drop the final extension from a RawFilePath -- --
--   >>> dropExtension "file.exe"
--   "file"
--   
--   >>> dropExtension "file"
--   "file"
--   
--   >>> dropExtension "/path/file.tar.gz"
--   "/path/file.tar"
--   
dropExtension :: RawFilePath -> RawFilePath -- | Add an extension to a RawFilePath -- --
--   >>> addExtension "file" ".exe"
--   "file.exe"
--   
--   >>> addExtension "file.tar" ".gz"
--   "file.tar.gz"
--   
--   >>> addExtension "/path/" ".ext"
--   "/path/.ext"
--   
addExtension :: RawFilePath -> ByteString -> RawFilePath -- | Check if a RawFilePath has an extension -- --
--   >>> hasExtension "file"
--   False
--   
--   >>> hasExtension "file.tar"
--   True
--   
--   >>> hasExtension "/path.part1/"
--   False
--   
hasExtension :: RawFilePath -> Bool -- | Operator version of addExtension (<.>) :: RawFilePath -> ByteString -> RawFilePath -- | Split a RawFilePath on the first extension. -- --
--   >>> splitExtensions "/path/file.tar.gz"
--   ("/path/file",".tar.gz")
--   
-- --
--   \path -> uncurry addExtension (splitExtensions path) == path
--   
splitExtensions :: RawFilePath -> (RawFilePath, ByteString) -- | Remove all extensions from a RawFilePath -- --
--   >>> dropExtensions "/path/file.tar.gz"
--   "/path/file"
--   
dropExtensions :: RawFilePath -> RawFilePath -- | Take all extensions from a RawFilePath -- --
--   >>> takeExtensions "/path/file.tar.gz"
--   ".tar.gz"
--   
takeExtensions :: RawFilePath -> ByteString -- | Drop the given extension from a FilePath, and the "." -- preceding it. Returns Nothing if the FilePath does not have the -- given extension, or Just and the part before the extension if -- it does. -- -- This function can be more predictable than dropExtensions, -- especially if the filename might itself contain . characters. -- --
--   >>> stripExtension "hs.o" "foo.x.hs.o"
--   Just "foo.x"
--   
--   >>> stripExtension "hi.o" "foo.x.hs.o"
--   Nothing
--   
--   >>> stripExtension ".c.d" "a.b.c.d"
--   Just "a.b"
--   
--   >>> stripExtension ".c.d" "a.b..c.d"
--   Just "a.b."
--   
--   >>> stripExtension "baz"  "foo.bar"
--   Nothing
--   
--   >>> stripExtension "bar"  "foobar"
--   Nothing
--   
-- --
--   \path -> stripExtension "" path == Just path
--   
-- --
--   \path -> dropExtension path  == fromJust (stripExtension (takeExtension path) path)
--   
-- --
--   \path -> dropExtensions path == fromJust (stripExtension (takeExtensions path) path)
--   
stripExtension :: ByteString -> RawFilePath -> Maybe RawFilePath -- | Split a RawFilePath into (path,file). combine is the -- inverse -- --
--   >>> splitFileName "path/file.txt"
--   ("path/","file.txt")
--   
--   >>> splitFileName "path/"
--   ("path/","")
--   
--   >>> splitFileName "file.txt"
--   ("./","file.txt")
--   
-- --
--   \path -> uncurry combine (splitFileName path) == path || fst (splitFileName path) == "./"
--   
splitFileName :: RawFilePath -> (RawFilePath, RawFilePath) -- | Get the file name -- --
--   >>> takeFileName "path/file.txt"
--   "file.txt"
--   
--   >>> takeFileName "path/"
--   ""
--   
takeFileName :: RawFilePath -> RawFilePath -- | Change the file name -- --
--   \path -> replaceFileName path (takeFileName path) == path
--   
replaceFileName :: RawFilePath -> ByteString -> RawFilePath -- | Drop the file name -- --
--   >>> dropFileName "path/file.txt"
--   "path/"
--   
--   >>> dropFileName "file.txt"
--   "./"
--   
dropFileName :: RawFilePath -> RawFilePath -- | Get the file name, without a trailing extension -- --
--   >>> takeBaseName "path/file.tar.gz"
--   "file.tar"
--   
--   >>> takeBaseName ""
--   ""
--   
takeBaseName :: RawFilePath -> ByteString -- | Change the base name -- --
--   >>> replaceBaseName "path/file.tar.gz" "bob"
--   "path/bob.gz"
--   
-- --
--   \path -> replaceBaseName path (takeBaseName path) == path
--   
replaceBaseName :: RawFilePath -> ByteString -> RawFilePath -- | Get the directory, moving up one level if it's already a directory -- --
--   >>> takeDirectory "path/file.txt"
--   "path"
--   
--   >>> takeDirectory "file"
--   "."
--   
--   >>> takeDirectory "/path/to/"
--   "/path/to"
--   
--   >>> takeDirectory "/path/to"
--   "/path"
--   
takeDirectory :: RawFilePath -> RawFilePath -- | Change the directory component of a RawFilePath -- --
--   \path -> replaceDirectory path (takeDirectory path) `equalFilePath` path || takeDirectory path == "."
--   
replaceDirectory :: RawFilePath -> ByteString -> RawFilePath -- | Join two paths together -- --
--   >>> combine "/" "file"
--   "/file"
--   
--   >>> combine "/path/to" "file"
--   "/path/to/file"
--   
--   >>> combine "file" "/absolute/path"
--   "/absolute/path"
--   
combine :: RawFilePath -> RawFilePath -> RawFilePath -- | Operator version of combine () :: RawFilePath -> RawFilePath -> RawFilePath -- | Split a path into a list of components: -- --
--   >>> splitPath "/path/to/file.txt"
--   ["/","path/","to/","file.txt"]
--   
-- --
--   \path -> BS.concat (splitPath path) == path
--   
splitPath :: RawFilePath -> [RawFilePath] -- | Join a split path back together -- --
--   \path -> joinPath (splitPath path) == path
--   
-- --
--   >>> joinPath ["path","to","file.txt"]
--   "path/to/file.txt"
--   
joinPath :: [RawFilePath] -> RawFilePath -- | Like splitPath, but without trailing slashes -- --
--   >>> splitDirectories "/path/to/file.txt"
--   ["/","path","to","file.txt"]
--   
--   >>> splitDirectories ""
--   []
--   
splitDirectories :: RawFilePath -> [RawFilePath] -- | Check if the last character of a RawFilePath is /. -- --
--   >>> hasTrailingPathSeparator "/path/"
--   True
--   
--   >>> hasTrailingPathSeparator "/"
--   True
--   
--   >>> hasTrailingPathSeparator "/path"
--   False
--   
hasTrailingPathSeparator :: RawFilePath -> Bool -- | Add a trailing path separator. -- --
--   >>> addTrailingPathSeparator "/path"
--   "/path/"
--   
--   >>> addTrailingPathSeparator "/path/"
--   "/path/"
--   
--   >>> addTrailingPathSeparator "/"
--   "/"
--   
addTrailingPathSeparator :: RawFilePath -> RawFilePath -- | Remove a trailing path separator -- --
--   >>> dropTrailingPathSeparator "/path/"
--   "/path"
--   
--   >>> dropTrailingPathSeparator "/path////"
--   "/path"
--   
--   >>> dropTrailingPathSeparator "/"
--   "/"
--   
--   >>> dropTrailingPathSeparator "//"
--   "/"
--   
dropTrailingPathSeparator :: RawFilePath -> RawFilePath -- | Normalise a file. -- --
--   >>> normalise "/file/\\test////"
--   "/file/\\test/"
--   
--   >>> normalise "/file/./test"
--   "/file/test"
--   
--   >>> normalise "/test/file/../bob/fred/"
--   "/test/file/../bob/fred/"
--   
--   >>> normalise "../bob/fred/"
--   "../bob/fred/"
--   
--   >>> normalise "./bob/fred/"
--   "bob/fred/"
--   
--   >>> normalise "./bob////.fred/./...///./..///#."
--   "bob/.fred/.../../#."
--   
--   >>> normalise "."
--   "."
--   
--   >>> normalise "./"
--   "./"
--   
--   >>> normalise "./."
--   "./"
--   
--   >>> normalise "/./"
--   "/"
--   
--   >>> normalise "/"
--   "/"
--   
--   >>> normalise "bob/fred/."
--   "bob/fred/"
--   
--   >>> normalise "//home"
--   "/home"
--   
normalise :: RawFilePath -> RawFilePath -- | Contract a filename, based on a relative path. Note that the resulting -- path will never introduce .. paths, as the presence of -- symlinks means ../b may not reach a/b if it starts -- from a/c. For a worked example see this blog post. -- --
--   >>> makeRelative "/directory" "/directory/file.ext"
--   "file.ext"
--   
--   >>> makeRelative "/Home" "/home/bob"
--   "/home/bob"
--   
--   >>> makeRelative "/home/" "/home/bob/foo/bar"
--   "bob/foo/bar"
--   
--   >>> makeRelative "/fred" "bob"
--   "bob"
--   
--   >>> makeRelative "/file/test" "/file/test/fred"
--   "fred"
--   
--   >>> makeRelative "/file/test" "/file/test/fred/"
--   "fred/"
--   
--   >>> makeRelative "some/path" "some/path/a/b/c"
--   "a/b/c"
--   
-- --
--   \p -> makeRelative p p == "."
--   
-- --
--   \p -> makeRelative (takeDirectory p) p `equalFilePath` takeFileName p
--   
-- -- prop x y -> equalFilePath x y || (isRelative x && -- makeRelative y x == x) || equalFilePath (y / makeRelative y x) -- x makeRelative :: RawFilePath -> RawFilePath -> RawFilePath -- | Equality of two filepaths. The filepaths are normalised and trailing -- path separators are dropped. -- --
--   >>> equalFilePath "foo" "foo"
--   True
--   
--   >>> equalFilePath "foo" "foo/"
--   True
--   
--   >>> equalFilePath "foo" "./foo"
--   True
--   
--   >>> equalFilePath "" ""
--   True
--   
--   >>> equalFilePath "foo" "/foo"
--   False
--   
--   >>> equalFilePath "foo" "FOO"
--   False
--   
--   >>> equalFilePath "foo" "../foo"
--   False
--   
-- --
--   \p -> equalFilePath p p
--   
equalFilePath :: RawFilePath -> RawFilePath -> Bool -- | Check if a path is relative -- --
--   \path -> isRelative path /= isAbsolute path
--   
isRelative :: RawFilePath -> Bool -- | Check if a path is absolute -- --
--   >>> isAbsolute "/path"
--   True
--   
--   >>> isAbsolute "path"
--   False
--   
--   >>> isAbsolute ""
--   False
--   
isAbsolute :: RawFilePath -> Bool -- | Is a FilePath valid, i.e. could you create a file like it? -- --
--   >>> isValid ""
--   False
--   
--   >>> isValid "\0"
--   False
--   
--   >>> isValid "/random_ path:*"
--   True
--   
isValid :: RawFilePath -> Bool -- | Take a FilePath and make it valid; does not change already valid -- FilePaths. -- --
--   >>> makeValid ""
--   "_"
--   
--   >>> makeValid "file\0name"
--   "file_name"
--   
-- --
--   \p -> if isValid p then makeValid p == p else makeValid p /= p
--   
-- --
--   \p -> isValid (makeValid p)
--   
makeValid :: RawFilePath -> RawFilePath -- | Is the given path a valid filename? This includes "." and "..". -- --
--   >>> isFileName "lal"
--   True
--   
--   >>> isFileName "."
--   True
--   
--   >>> isFileName ".."
--   True
--   
--   >>> isFileName ""
--   False
--   
--   >>> isFileName "\0"
--   False
--   
--   >>> isFileName "/random_ path:*"
--   False
--   
isFileName :: RawFilePath -> Bool -- | Check if the filepath has any parent directories in it. -- --
--   >>> hasParentDir "/.."
--   True
--   
--   >>> hasParentDir "foo/bar/.."
--   True
--   
--   >>> hasParentDir "foo/../bar/."
--   True
--   
--   >>> hasParentDir "foo/bar"
--   False
--   
--   >>> hasParentDir "foo"
--   False
--   
--   >>> hasParentDir ""
--   False
--   
--   >>> hasParentDir ".."
--   False
--   
hasParentDir :: RawFilePath -> Bool -- | Whether the file is a hidden file. -- --
--   >>> hiddenFile ".foo"
--   True
--   
--   >>> hiddenFile "..foo.bar"
--   True
--   
--   >>> hiddenFile "some/path/.bar"
--   True
--   
--   >>> hiddenFile "..."
--   True
--   
--   >>> hiddenFile "dod.bar"
--   False
--   
--   >>> hiddenFile "."
--   False
--   
--   >>> hiddenFile ".."
--   False
--   
--   >>> hiddenFile ""
--   False
--   
hiddenFile :: RawFilePath -> Bool -- | Traversal and read operations on directories. module System.Posix.Directory.Traversals -- | Gets all directory contents (not recursively). getDirectoryContents :: RawFilePath -> IO [(DirType, RawFilePath)] -- | Like getDirectoryContents except for a file descriptor. -- -- To avoid complicated error checks, the file descriptor is -- always closed, even if fdOpendir fails. Usually, this -- only happens on successful fdOpendir and after the directory -- stream is closed. Also see the manpage of fdopendir(3) for -- more details. getDirectoryContents' :: Fd -> IO [(DirType, RawFilePath)] -- | Get all files from a directory and its subdirectories. -- -- Upon entering a directory, allDirectoryContents will get all -- entries strictly. However the returned list is lazy in that -- directories will only be accessed on demand. -- -- Follows symbolic links for the input dir. allDirectoryContents :: RawFilePath -> IO [RawFilePath] -- | Get all files from a directory and its subdirectories strictly. -- -- Follows symbolic links for the input dir. allDirectoryContents' :: RawFilePath -> IO [RawFilePath] -- | Recursively apply the action to the parent directory and all -- files/subdirectories. -- -- This function allows for memory-efficient traversals. -- -- Follows symbolic links for the input dir. traverseDirectory :: (s -> RawFilePath -> IO s) -> s -> RawFilePath -> IO s readDirEnt :: DirStream -> IO (DirType, RawFilePath) packDirStream :: Ptr CDir -> DirStream unpackDirStream :: DirStream -> Ptr CDir -- | Binding to fdopendir(3). fdOpendir :: Fd -> IO DirStream -- | return the canonicalized absolute pathname -- -- like canonicalizePath, but uses realpath(3) realpath :: RawFilePath -> IO RawFilePath -- | Internal types and functions. module HPath.Internal -- | Path of some base and type. -- -- Internally is a string. The string can be of two formats only: -- --
    --
  1. without trailing path separator: file.txt, -- foo/bar.txt, /foo/bar.txt
  2. --
  3. with trailing path separator: foo/, -- /foo/bar/
  4. --
-- -- There are no duplicate path separators //, no .., no -- ./, no ~/, etc. data Path b MkPath :: ByteString -> Path b class RelC m instance GHC.Classes.Eq (HPath.Internal.Path b) instance GHC.Classes.Ord (HPath.Internal.Path b) instance GHC.Show.Show (HPath.Internal.Path b) instance Control.DeepSeq.NFData (HPath.Internal.Path b) -- | Support for well-typed paths. module HPath -- | An absolute path. data Abs -- | Path of some base and type. -- -- Internally is a string. The string can be of two formats only: -- --
    --
  1. without trailing path separator: file.txt, -- foo/bar.txt, /foo/bar.txt
  2. --
  3. with trailing path separator: foo/, -- /foo/bar/
  4. --
-- -- There are no duplicate path separators //, no .., no -- ./, no ~/, etc. data Path b -- | A relative path; one without a root. data Rel -- | A filename, without any /. data Fn -- | Exception when parsing a location. data PathParseException data PathException -- | Get a location for an absolute path. Produces a normalised path. -- -- Throws: PathParseException -- --
--   >>> parseAbs "/abc"          :: Maybe (Path Abs)
--   Just "/abc"
--   
--   >>> parseAbs "/"             :: Maybe (Path Abs)
--   Just "/"
--   
--   >>> parseAbs "/abc/def"      :: Maybe (Path Abs)
--   Just "/abc/def"
--   
--   >>> parseAbs "/abc/def/.///" :: Maybe (Path Abs)
--   Just "/abc/def/"
--   
--   >>> parseAbs "abc"           :: Maybe (Path Abs)
--   Nothing
--   
--   >>> parseAbs ""              :: Maybe (Path Abs)
--   Nothing
--   
--   >>> parseAbs "/abc/../foo"   :: Maybe (Path Abs)
--   Nothing
--   
parseAbs :: MonadThrow m => ByteString -> m (Path Abs) -- | Parses a filename. Filenames must not contain slashes. Excludes -- . and '..'. -- -- Throws: PathParseException -- --
--   >>> parseFn "abc"        :: Maybe (Path Fn)
--   Just "abc"
--   
--   >>> parseFn "..."        :: Maybe (Path Fn)
--   Just "..."
--   
--   >>> parseFn "def/"       :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn "abc/def"    :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn "abc/def/."  :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn "/abc"       :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn ""           :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn "abc/../foo" :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn "."          :: Maybe (Path Fn)
--   Nothing
--   
--   >>> parseFn ".."         :: Maybe (Path Fn)
--   Nothing
--   
parseFn :: MonadThrow m => ByteString -> m (Path Fn) -- | Get a location for a relative path. Produces a normalised path. -- -- Note that filepath may contain any number of ./ but -- may not consist solely of ./. It also may not contain a -- single .. anywhere. -- -- Throws: PathParseException -- --
--   >>> parseRel "abc"        :: Maybe (Path Rel)
--   Just "abc"
--   
--   >>> parseRel "def/"       :: Maybe (Path Rel)
--   Just "def/"
--   
--   >>> parseRel "abc/def"    :: Maybe (Path Rel)
--   Just "abc/def"
--   
--   >>> parseRel "abc/def/."  :: Maybe (Path Rel)
--   Just "abc/def/"
--   
--   >>> parseRel "/abc"       :: Maybe (Path Rel)
--   Nothing
--   
--   >>> parseRel ""           :: Maybe (Path Rel)
--   Nothing
--   
--   >>> parseRel "abc/../foo" :: Maybe (Path Rel)
--   Nothing
--   
--   >>> parseRel "."          :: Maybe (Path Rel)
--   Nothing
--   
--   >>> parseRel ".."         :: Maybe (Path Rel)
--   Nothing
--   
parseRel :: MonadThrow m => ByteString -> m (Path Rel) -- | Convert an absolute Path to a ByteString type. fromAbs :: Path Abs -> ByteString -- | Convert a relative Path to a ByteString type. fromRel :: RelC r => Path r -> ByteString -- | Convert any Path to a ByteString type. toFilePath :: Path b -> ByteString -- | Append two paths. -- -- The second argument must always be a relative path, which ensures that -- undefinable things like `"abc" <> "/def"` cannot happen. -- -- Technically, the first argument can be a path that points to a -- non-directory, because this library is IO-agnostic and makes no -- assumptions about file types. -- --
--   >>> (MkPath "/")        </> (MkPath "file"     :: Path Rel)
--   "/file"
--   
--   >>> (MkPath "/path/to") </> (MkPath "file"     :: Path Rel)
--   "/path/to/file"
--   
--   >>> (MkPath "/")        </> (MkPath "file/lal" :: Path Rel)
--   "/file/lal"
--   
--   >>> (MkPath "/")        </> (MkPath "file/"    :: Path Rel)
--   "/file/"
--   
() :: RelC r => Path b -> Path r -> Path b -- | Extract the file part of a path. -- -- The following properties hold: -- --
--   basename (p </> a) == basename a
--   
-- -- Throws: PathException if given the root path "/" -- --
--   >>> basename (MkPath "/abc/def/dod") :: Maybe (Path Fn)
--   Just "dod"
--   
--   >>> basename (MkPath "/")            :: Maybe (Path Fn)
--   Nothing
--   
basename :: MonadThrow m => Path b -> m (Path Fn) -- | Extract the directory name of a path. -- -- The following properties hold: -- --
--   dirname (p </> a) == dirname p
--   
-- --
--   >>> dirname (MkPath "/abc/def/dod")
--   "/abc/def"
--   
--   >>> dirname (MkPath "/")
--   "/"
--   
dirname :: Path Abs -> Path Abs -- | Is p a parent of the given location? Implemented in terms of -- stripDir. The bases must match. -- --
--   >>> (MkPath "/lal/lad")     `isParentOf` (MkPath "/lal/lad/fad")
--   True
--   
--   >>> (MkPath "lal/lad")      `isParentOf` (MkPath "lal/lad/fad")
--   True
--   
--   >>> (MkPath "/")            `isParentOf` (MkPath "/")
--   False
--   
--   >>> (MkPath "/lal/lad/fad") `isParentOf` (MkPath "/lal/lad")
--   False
--   
--   >>> (MkPath "fad")          `isParentOf` (MkPath "fad")
--   False
--   
isParentOf :: Path b -> Path b -> Bool -- | Get all parents of a path. -- --
--   >>> getAllParents (MkPath "/abs/def/dod")
--   ["/abs/def","/abs","/"]
--   
--   >>> getAllParents (MkPath "/")
--   []
--   
getAllParents :: Path Abs -> [Path Abs] -- | Strip directory from path, making it relative to that directory. -- Throws Couldn'tStripPrefixDir if directory is not a parent of -- the path. -- -- The bases must match. -- --
--   >>> (MkPath "/lal/lad")     `stripDir` (MkPath "/lal/lad/fad") :: Maybe (Path Rel)
--   Just "fad"
--   
--   >>> (MkPath "lal/lad")      `stripDir` (MkPath "lal/lad/fad")  :: Maybe (Path Rel)
--   Just "fad"
--   
--   >>> (MkPath "/")            `stripDir` (MkPath "/")            :: Maybe (Path Rel)
--   Nothing
--   
--   >>> (MkPath "/lal/lad/fad") `stripDir` (MkPath "/lal/lad")     :: Maybe (Path Rel)
--   Nothing
--   
--   >>> (MkPath "fad")          `stripDir` (MkPath "fad")          :: Maybe (Path Rel)
--   Nothing
--   
stripDir :: MonadThrow m => Path b -> Path b -> m (Path Rel) withAbsPath :: Path Abs -> (ByteString -> IO a) -> IO a withRelPath :: Path Rel -> (ByteString -> IO a) -> IO a withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a instance GHC.Show.Show HPath.PathException instance GHC.Show.Show HPath.PathParseException instance GHC.Exception.Exception HPath.PathParseException instance GHC.Exception.Exception HPath.PathException instance HPath.Internal.RelC HPath.Rel instance HPath.Internal.RelC HPath.Fn -- | Provides error handling. module HPath.IO.Errors data HPathIOException FileDoesNotExist :: ByteString -> HPathIOException DirDoesNotExist :: ByteString -> HPathIOException SameFile :: ByteString -> ByteString -> HPathIOException DestinationInSource :: ByteString -> ByteString -> HPathIOException FileDoesExist :: ByteString -> HPathIOException DirDoesExist :: ByteString -> HPathIOException InvalidOperation :: String -> HPathIOException Can'tOpenDirectory :: ByteString -> HPathIOException CopyFailed :: String -> HPathIOException isFileDoesNotExist :: HPathIOException -> Bool isDirDoesNotExist :: HPathIOException -> Bool isSameFile :: HPathIOException -> Bool isDestinationInSource :: HPathIOException -> Bool isFileDoesExist :: HPathIOException -> Bool isDirDoesExist :: HPathIOException -> Bool isInvalidOperation :: HPathIOException -> Bool isCan'tOpenDirectory :: HPathIOException -> Bool isCopyFailed :: HPathIOException -> Bool throwFileDoesExist :: Path Abs -> IO () throwDirDoesExist :: Path Abs -> IO () throwFileDoesNotExist :: Path Abs -> IO () throwDirDoesNotExist :: Path Abs -> IO () -- | Uses isSameFile and throws SameFile if it returns True. throwSameFile :: Path Abs -> Path Abs -> IO () -- | Check if the files are the same by examining device and file id. This -- follows symbolic links. sameFile :: Path Abs -> Path Abs -> IO Bool -- | Checks whether the destination directory is contained within the -- source directory by comparing the device+file ID of the source -- directory with all device+file IDs of the parent directories of the -- destination. throwDestinationInSource :: Path Abs -> Path Abs -> IO () -- | Checks if the given file exists and is not a directory. Does not -- follow symlinks. doesFileExist :: Path Abs -> IO Bool -- | Checks if the given file exists and is a directory. Does not follow -- symlinks. doesDirectoryExist :: Path Abs -> IO Bool -- | Checks whether a file or folder is writable. isWritable :: Path Abs -> IO Bool -- | Checks whether the directory at the given path exists and can be -- opened. This invokes openDirStream which follows symlinks. canOpenDirectory :: Path Abs -> IO Bool -- | Throws a Can'tOpenDirectory HPathIOException if the directory -- at the given path cannot be opened. throwCantOpenDirectory :: Path Abs -> IO () -- | Carries out an action, then checks if there is an IOException and a -- specific errno. If so, then it carries out another action, otherwise -- it rethrows the error. catchErrno :: [Errno] -> IO a -> IO a -> IO a -- | Execute the given action and retrow IO exceptions as a new Exception -- that have the given errno. If errno does not match the exception is -- rethrown as is. rethrowErrnoAs :: Exception e => [Errno] -> e -> IO a -> IO a -- | Like catchIOError, with arguments swapped. handleIOError :: (IOError -> IO a) -> IO a -> IO a -- | Like bracket, but allows to have different clean-up actions -- depending on whether the in-between computation has raised an -- exception or not. bracketeer :: IO a -> (a -> IO b) -> (a -> IO b) -> (a -> IO c) -> IO c reactOnError :: IO a -> [(IOErrorType, IO a)] -> [(HPathIOException, IO a)] -> IO a instance Data.Data.Data HPath.IO.Errors.HPathIOException instance GHC.Classes.Eq HPath.IO.Errors.HPathIOException instance GHC.Show.Show HPath.IO.Errors.HPathIOException instance GHC.Exception.Exception HPath.IO.Errors.HPathIOException -- | This module provides high-level IO related file operations like copy, -- delete, move and so on. It only operates on Path Abs which -- guarantees us well-typed paths which are absolute. -- -- Some functions are just path-safe wrappers around unix functions, -- others have stricter exception handling and some implement -- functionality that doesn't have a unix counterpart (like -- copyDirRecursive). -- -- Some of these operations are due to their nature not atomic, -- which means they may do multiple syscalls which form one context. Some -- of them also have to examine the filetypes explicitly before the -- syscalls, so a reasonable decision can be made. That means the result -- is undefined if another process changes that context while the -- non-atomic operation is still happening. However, where possible, as -- few syscalls as possible are used and the underlying exception -- handling is kept. -- -- Note: BlockDevice, CharacterDevice, NamedPipe and -- Socket are not explicitly supported right now. Calling any of -- these functions on such a file may throw an exception or just do -- nothing. module HPath.IO data FileType Directory :: FileType RegularFile :: FileType SymbolicLink :: FileType BlockDevice :: FileType CharacterDevice :: FileType NamedPipe :: FileType Socket :: FileType -- | Copies a directory recursively to the given destination. Does not -- follow symbolic links. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- copyDirRecursive :: Path Abs -> Path Abs -> IO () -- | Like copyDirRecursive except it overwrites contents of -- directories if any. -- -- Throws: -- -- copyDirRecursiveOverwrite :: Path Abs -> Path Abs -> IO () -- | Recreate a symlink. -- -- Throws: -- -- -- -- Note: calls symlink recreateSymlink :: Path Abs -> Path Abs -> IO () -- | Copies the given regular file to the given destination. Neither -- follows symbolic links, nor accepts them. For "copying" symbolic -- links, use recreateSymlink instead. -- -- Throws: -- -- -- -- Note: calls sendfile and possibly read/write -- as fallback copyFile :: Path Abs -> Path Abs -> IO () -- | Like copyFile except it overwrites the destination if it -- already exists. This also works if source and destination are the same -- file. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- -- -- Note: calls sendfile and possibly read/write -- as fallback copyFileOverwrite :: Path Abs -> Path Abs -> IO () -- | Copies anything. In case of a symlink, it is just recreated, even if -- it points to a directory. -- -- Safety/reliability concerns: -- -- easyCopy :: Path Abs -> Path Abs -> IO () -- | Like easyCopy except it overwrites the destination if it -- already exists. For directories, this overwrites contents without -- pruning them, so the resulting directory may have more files than have -- been copied. easyCopyOverwrite :: Path Abs -> Path Abs -> IO () -- | Deletes the given file. Raises eISDIR if run on a directory. -- Does not follow symbolic links. -- -- Throws: -- -- deleteFile :: Path Abs -> IO () -- | Deletes the given directory, which must be empty, never symlinks. -- -- Throws: -- -- -- -- Notes: calls rmdir deleteDir :: Path Abs -> IO () -- | Deletes the given directory recursively. Does not follow symbolic -- links. Tries deleteDir first before attemtping a recursive -- deletion. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- deleteDirRecursive :: Path Abs -> IO () -- | Deletes a file, directory or symlink, whatever it may be. In case of -- directory, performs recursive deletion. In case of a symlink, the -- symlink file is deleted. -- -- Safety/reliability concerns: -- -- easyDelete :: Path Abs -> IO () -- | Opens a file appropriately by invoking xdg-open. The file type is not -- checked. This forks a process. openFile :: Path Abs -> IO ProcessID -- | Executes a program with the given arguments. This forks a process. executeFile :: Path Abs -> [ByteString] -> IO ProcessID -- | Create an empty regular file at the given directory with the given -- filename. -- -- Throws: -- -- createRegularFile :: Path Abs -> IO () -- | Create an empty directory at the given directory with the given -- filename. -- -- Throws: -- -- createDir :: Path Abs -> IO () -- | Create a symlink. -- -- Throws: -- -- -- -- Note: calls symlink createSymlink :: Path Abs -> ByteString -> IO () -- | Rename a given file with the provided filename. Destination and source -- must be on the same device, otherwise eXDEV will be raised. -- -- Does not follow symbolic links, but renames the symbolic link file. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- -- -- Note: calls rename (but does not allow to rename over existing -- files) renameFile :: Path Abs -> Path Abs -> IO () -- | Move a file. This also works across devices by copy-delete fallback. -- And also works on directories. -- -- Does not follow symbolic links, but renames the symbolic link file. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- -- -- Note: calls rename (but does not allow to rename over existing -- files) moveFile :: Path Abs -> Path Abs -> IO () -- | Like moveFile, but overwrites the destination if it exists. -- -- Does not follow symbolic links, but renames the symbolic link file. -- -- Safety/reliability concerns: -- -- -- -- Throws: -- -- -- -- Note: calls rename (but does not allow to rename over existing -- files) moveFileOverwrite :: Path Abs -> Path Abs -> IO () -- | Default permissions for a new file. newFilePerms :: FileMode -- | Default permissions for a new directory. newDirPerms :: FileMode -- | Gets all filenames of the given directory. This excludes "." and "..". -- This version does not follow symbolic links. -- -- Throws: -- -- getDirsFiles :: Path Abs -> IO [Path Abs] -- | Get the file type of the file located at the given path. Does not -- follow symbolic links. -- -- Throws: -- -- getFileType :: Path Abs -> IO FileType -- | Applies realpath on the given absolute path. -- -- Throws: -- -- canonicalizePath :: Path Abs -> IO (Path Abs) instance GHC.Show.Show HPath.IO.FileType instance GHC.Classes.Eq HPath.IO.FileType