1- {-# LANGUAGE BangPatterns #-}
21{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DeriveGeneric #-}
43{-# LANGUAGE DerivingVia #-}
@@ -18,6 +17,9 @@ module Dhall.DirectoryTree
1817 ( -- * Filesystem
1918 toDirectoryTree
2019 , FilesystemError (.. )
20+
21+ -- * Exported for testing only
22+ , directoryTreeType
2123 ) where
2224
2325import Control.Applicative (empty )
@@ -257,10 +259,12 @@ toDirectoryTree allowSeparators path expression = case expression of
257259 where
258260 unexpectedExpression = expression
259261
262+ -- | The type of a fixpoint directory tree expression.
260263directoryTreeType :: Expector (Expr Src Void )
261264directoryTreeType = Pi Nothing " result" (Const Type )
262265 <$> (Pi Nothing " make" <$> makeType <*> pure (App List (Var (V " result" 0 ))))
263266
267+ -- | The type of make part of a fixpoint directory tree expression.
264268makeType :: Expector (Expr Src Void )
265269makeType = Record . Map. fromList <$> sequenceA
266270 [ makeConstructor " directory" (Decode. auto :: Decoder DirectoryEntry )
@@ -292,8 +296,8 @@ instance FromDhall FilesystemEntry where
292296 expr -> Decode. typeError (expected (Decode. autoWith normalizer :: Decoder FilesystemEntry )) expr
293297 }
294298
295- -- | A generic filesystem entry. This type holds the metadata that apply to all entries.
296- -- It is parametric over the content of such an entry.
299+ -- | A generic filesystem entry. This type holds the metadata that apply to all
300+ -- entries. It is parametric over the content of such an entry.
297301data Entry a = Entry
298302 { entryName :: String
299303 , entryContent :: a
@@ -434,7 +438,8 @@ applyMetadata entry fp = do
434438 unless (mode' == mode) $
435439 Posix. setFileMode fp $ modeToFileMode mode'
436440
437- -- | Calculate the new `Mode` from the current mode and the changes specified by the user.
441+ -- | Calculate the new `Mode` from the current mode and the changes specified by
442+ -- the user.
438443updateModeWith :: Mode Identity -> Mode Maybe -> Mode Identity
439444updateModeWith x y = Mode
440445 { modeUser = combine modeUser modeUser
@@ -444,7 +449,8 @@ updateModeWith x y = Mode
444449 where
445450 combine f g = maybe (f x) (Identity . updateAccessWith (runIdentity $ f x)) (g y)
446451
447- -- | Calculate the new `Access` from the current permissions and the changes specified by the user.
452+ -- | Calculate the new `Access` from the current permissions and the changes
453+ -- specified by the user.
448454updateAccessWith :: Access Identity -> Access Maybe -> Access Identity
449455updateAccessWith x y = Access
450456 { accessExecute = combine accessExecute accessExecute
@@ -454,7 +460,8 @@ updateAccessWith x y = Access
454460 where
455461 combine f g = maybe (f x) Identity (g y)
456462
457- -- | Convert a filesystem mode given as a bitmask (`FileMode`) to an ADT (`Mode`).
463+ -- | Convert a filesystem mode given as a bitmask (`FileMode`) to an ADT
464+ -- (`Mode`).
458465fileModeToMode :: FileMode -> Mode Identity
459466fileModeToMode mode = Mode
460467 { modeUser = Identity $ Access
@@ -474,7 +481,8 @@ fileModeToMode mode = Mode
474481 }
475482 }
476483
477- -- | Convert a filesystem mode given as an ADT (`Mode`) to a bitmask (`FileMode`).
484+ -- | Convert a filesystem mode given as an ADT (`Mode`) to a bitmask
485+ -- (`FileMode`).
478486modeToFileMode :: Mode Identity -> FileMode
479487modeToFileMode mode = foldr Posix. unionFileModes Posix. nullFileMode $
480488 [ Posix. ownerExecuteMode | runIdentity $ accessExecute (runIdentity $ modeUser mode) ] <>
0 commit comments