headroom-0.4.1.0: License Header Manager
Copyright(c) 2019-2021 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.FileSystem

Description

Module providing functions for working with the local file system, its file and directories.

Synopsis

Type Aliases

type CreateDirectoryFn m Source #

Arguments

 = FilePath

path of new directory

-> m ()

IO action result

Type of a function that creates new empty directory on the given path.

type DoesFileExistFn m Source #

Arguments

 = FilePath

path to check

-> m Bool

whether the given path is existing file

Type of a function that returns True if the argument file exists and is not a directory, and False otherwise.

type FindFilesFn m Source #

Arguments

 = FilePath

path to search

-> (FilePath -> Bool)

predicate to match filename

-> m [FilePath]

found files

Type of a function that recursively finds files on given path whose filename matches the predicate.

type FindFilesByExtsFn m Source #

Arguments

 = FilePath

path to search

-> [Text]

list of file extensions (without dot)

-> m [FilePath]

list of found files

Type of a function that recursively finds files on given path by file extensions.

type FindFilesByTypesFn m Source #

Arguments

 = CtHeadersConfig

configuration of license headers

-> [FileType]

list of file types

-> FilePath

path to search

-> m [FilePath]

list of found files

Type of a function that recursively find files on given path by their file types.

type GetCurrentDirectoryFn m = m FilePath Source #

Type of a function that obtains the current working directory as an absolute path.

type ListFilesFn m Source #

Arguments

 = FilePath

path to search

-> m [FilePath]

list of found files

Type of a function that recursively find all files on given path. If file reference is passed instead of directory, such file path is returned.

type LoadFileFn m Source #

Arguments

 = FilePath

file path

-> m Text

file content

Type of a function that loads file content in UTF8 encoding.

Polymorphic Record

data FileSystem m Source #

Polymorphic record composed of file system IO function types, allowing to abstract over concrete implementation. Whenever you need to use effectful functions from this module, consider using this record instead of using them directly, as it allows you to use different records for production code and for testing, which is not as easy if you wire some of the provided functions directly.

Constructors

FileSystem 

Fields

Instances

Instances details
Has (FileSystem (RIO Env)) Env Source # 
Instance details

Defined in Headroom.Command.Init

mkFileSystem :: MonadIO m => FileSystem m Source #

Creates new FileSystem that performs actual disk IO operations.

Traversing the File System

findFiles :: MonadIO m => FindFilesFn m Source #

Recursively finds files on given path whose filename matches the predicate.

findFilesByExts :: MonadIO m => FindFilesByExtsFn m Source #

Recursively finds files on given path by file extensions.

findFilesByTypes :: MonadIO m => FindFilesByTypesFn m Source #

Recursively find files on given path by their file types.

listFiles :: MonadIO m => ListFilesFn m Source #

Recursively find all files on given path. If file reference is passed instead of directory, such file path is returned.

loadFile :: MonadIO m => LoadFileFn m Source #

Loads file content in UTF8 encoding.

Working with Files Metadata

fileExtension Source #

Arguments

:: FilePath

path from which to extract file extension

-> Maybe Text

extracted file extension

Returns file extension for given path (if file), or nothing otherwise.

>>> fileExtension "path/to/some/file.txt"
Just "txt"

Other

excludePaths Source #

Arguments

:: [Regex]

patterns describing paths to exclude

-> [FilePath]

list of file paths

-> [FilePath]

resulting list of file paths

Takes list of patterns and file paths and returns list of file paths where those matching the given patterns are excluded.

>>> :set -XQuasiQuotes
>>> import Headroom.Data.Regex (re)
>>> excludePaths [[re|\.hidden|], [re|zzz|]] ["foo/.hidden", "test/bar", "x/zzz/e"]
["test/bar"]