charon-0.1: Template
Safe HaskellSafe-Inferred
LanguageGHC2021

Charon.Data.Paths

Description

Provides functionality for distinguishing path types.

Synopsis

Types

newtype PathI (i :: PathIndex) Source #

Indexed OsPath so that we can prevent mixing up different filepaths.

Constructors

MkPathI 

Fields

Instances

Instances details
(Dysfunctional "unPathI" k (PathI i1) (PathI i2) a b, k ~ An_Iso, a ~ OsPath, b ~ OsPath) => LabelOptic "unPathI" k (PathI i1) (PathI i2) a b Source # 
Instance details

Defined in Charon.Data.Paths

Methods

labelOptic :: Optic k NoIx (PathI i1) (PathI i2) a b Source #

Generic (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Associated Types

type Rep (PathI i) :: Type -> Type #

Methods

from :: PathI i -> Rep (PathI i) x #

to :: Rep (PathI i) x -> PathI i #

Show (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Methods

showsPrec :: Int -> PathI i -> ShowS #

show :: PathI i -> String #

showList :: [PathI i] -> ShowS #

Serial (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Associated Types

type DecodeExtra (PathI i) Source #

NFData (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Methods

rnf :: PathI i -> () #

Eq (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Methods

(==) :: PathI i -> PathI i -> Bool #

(/=) :: PathI i -> PathI i -> Bool #

Ord (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Methods

compare :: PathI i -> PathI i -> Ordering #

(<) :: PathI i -> PathI i -> Bool #

(<=) :: PathI i -> PathI i -> Bool #

(>) :: PathI i -> PathI i -> Bool #

(>=) :: PathI i -> PathI i -> Bool #

max :: PathI i -> PathI i -> PathI i #

min :: PathI i -> PathI i -> PathI i #

Hashable (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

Methods

hashWithSalt :: Int -> PathI i -> Int Source #

hash :: PathI i -> Int Source #

type Rep (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

type Rep (PathI i) = D1 ('MetaData "PathI" "Charon.Data.Paths" "charon-0.1-inplace" 'True) (C1 ('MetaCons "MkPathI" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPathI") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OsPath)))
type DecodeExtra (PathI i) Source # 
Instance details

Defined in Charon.Data.Paths

type DecodeExtra (PathI i) = ()

data PathIndex Source #

Types of filepaths used in Charon.

Constructors

TrashHome

The trash directory.

TrashLog

The trash log file.

TrashDirFiles

The directory to the trash files themselves i.e. trash/files.

TrashDirInfo

The directory to the trash info files i.e. trash/info.

TrashEntryPath

The full trash path i.e. <trash-home>/files/'<trash-name>.

TrashEntryInfo

The full trash info path i.e. <trash-home>/info/'<trash-name>.trashinfo.

TrashEntryFileName

The name corresponding to some file/directory in the trash directory.

TrashEntryOriginalPath

The original path for some file/directory in the trash directory.

Functions

Specific

isRoot :: MonadThrow m => PathI i -> m Bool Source #

Returns true if the path is the root.

isRoot' :: MonadThrow m => OsPath -> m Bool Source #

Returns true if the path is the root.

isDots :: MonadThrow m => PathI i -> m Bool Source #

Returns true if the path ends in nothing but dots e.g. pathtodots...

toString :: PathI i -> String Source #

PathI to String. Attempts decoding for nicer display.

General

These functions allows for lifting arbitrary OsPath functions onto our PathI. Note that this can easily invalidate any invariants we would like to hold (e.g. appending a path can turn a directory into a file), so caution must be exercised.

showPaths :: [PathI a] -> String Source #

Pretty-print a list of paths.

>>> showPaths ["one", "two"]
"one, two"

reindex :: PathI i -> PathI j Source #

Modifies the index.

(<//>) :: PathI i1 -> PathI i2 -> PathI i3 infixr 5 Source #

(</>) lifted to PathI. Notice the index can change, so take care.

(<//) :: PathI i1 -> OsPath -> PathI i2 infixl 5 Source #

(//>) :: OsPath -> PathI i1 -> PathI i2 infixl 5 Source #

applyPathI :: HasCallStack => (HasCallStack => OsPath -> a) -> PathI i -> a Source #

Lifts an OsPath function to PathI.

liftPathI :: (OsPath -> OsPath) -> PathI i -> PathI j Source #

Lifts an OsPath transformation to PathI, allowing for the index to change.

liftPathI' :: (OsPath -> OsPath) -> PathI i -> PathI i Source #

liftPathI specialized to the same index. This should be preferred as the former is easier to use incorrectly.

liftPathIF :: (Functor f, HasCallStack) => (HasCallStack => OsPath -> f OsPath) -> PathI i -> f (PathI j) Source #

Lifts an effectful FilePath transformation to PathI.

liftPathIF' :: Functor f => (HasCallStack => OsPath -> f OsPath) -> PathI i -> f (PathI i) Source #

liftPathIF specialized to the same index. This should be preferred as the former is easier to use incorrectly.