1+ {-# LANGUAGE CPP #-}
12{-# LANGUAGE OverloadedLists #-}
23{-# LANGUAGE OverloadedStrings #-}
34{-# LANGUAGE RecordWildCards #-}
@@ -54,8 +55,12 @@ import qualified Prettyprinter as Pretty
5455import qualified Prettyprinter.Render.String as Pretty
5556import qualified System.Directory as Directory
5657import qualified System.FilePath as FilePath
58+ #ifdef mingw32_HOST_OS
59+ import System.IO.Error (illegalOperationErrorType , mkIOError )
60+ #else
61+ import qualified System.Posix.User as Posix
62+ #endif
5763import qualified System.PosixCompat.Files as Posix
58- import qualified System.PosixCompat.User as Posix
5964
6065{-| Attempt to transform a Dhall record into a directory tree where:
6166
@@ -263,12 +268,24 @@ makeType = Record . Map.fromList <$> sequenceA
263268-- | Resolve a `User` to a numerical id.
264269getUser :: User -> IO UserID
265270getUser (UserId uid) = return uid
266- getUser (UserName name) = Posix. userID <$> Posix. getUserEntryForName name
271+ getUser (UserName name) =
272+ #ifdef mingw32_HOST_OS
273+ ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
274+ where x = " System.Posix.User.getUserEntryForName: not supported"
275+ #else
276+ Posix. userID <$> Posix. getUserEntryForName name
277+ #endif
267278
268279-- | Resolve a `Group` to a numerical id.
269280getGroup :: Group -> IO GroupID
270281getGroup (GroupId gid) = return gid
271- getGroup (GroupName name) = Posix. groupID <$> Posix. getGroupEntryForName name
282+ getGroup (GroupName name) =
283+ #ifdef mingw32_HOST_OS
284+ ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
285+ where x = " System.Posix.User.getGroupEntryForName: not supported"
286+ #else
287+ Posix. groupID <$> Posix. getGroupEntryForName name
288+ #endif
272289
273290-- | Process a `FilesystemEntry`. Writes the content to disk and apply the
274291-- metadata to the newly created item.
@@ -409,57 +426,57 @@ instance Show FilesystemError where
409426 Pretty. renderString (Dhall.Pretty. layout message)
410427 where
411428 message =
412- Util. _ERROR <> " : Not a valid directory tree expression \n \
413- \ \n \
414- \Explanation: Only a subset of Dhall expressions can be converted to a directory \n \
415- \tree. Specifically, record literals or maps can be converted to directories, \n \
416- \❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n \
417- \❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n \
418- \they are an alternative which has a non-nullary constructor whose argument is of \n \
419- \an otherwise convertible type. Furthermore, there is a more advanced approach to \n \
420- \constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n \
421- \documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n \
422- \further information on that. \n \
423- \No other type of value can be translated to a directory tree. \n \
424- \ \n \
425- \For example, this is a valid expression that can be translated to a directory \n \
426- \tree: \n \
427- \ \n \
428- \ \n \
429- \ ┌──────────────────────────────────┐ \n \
430- \ │ { `example.json` = \" [1, true]\" } │ \n \
431- \ └──────────────────────────────────┘ \n \
432- \ \n \
433- \ \n \
434- \In contrast, the following expression is not allowed due to containing a \n \
435- \❰Natural❱ field, which cannot be translated in this way: \n \
436- \ \n \
437- \ \n \
438- \ ┌───────────────────────┐ \n \
439- \ │ { `example.txt` = 1 } │ \n \
440- \ └───────────────────────┘ \n \
441- \ \n \
442- \ \n \
443- \Note that key names cannot contain path separators: \n \
444- \ \n \
445- \ \n \
446- \ ┌─────────────────────────────────────┐ \n \
447- \ │ { `directory/example.txt` = \" ABC\" } │ Invalid: Key contains a forward slash\n \
448- \ └─────────────────────────────────────┘ \n \
449- \ \n \
450- \ \n \
451- \Instead, you need to refactor the expression to use nested records instead: \n \
452- \ \n \
453- \ \n \
454- \ ┌───────────────────────────────────────────┐ \n \
455- \ │ { directory = { `example.txt` = \" ABC\" } } │ \n \
456- \ └───────────────────────────────────────────┘ \n \
457- \ \n \
458- \ \n \
459- \You tried to translate the following expression to a directory tree: \n \
460- \ \n \
461- \" <> Util. insert unexpectedExpression <> " \n \
462- \ \n \
429+ Util. _ERROR <> " : Not a valid directory tree expression \n\\
430+ \ \n\\
431+ \Explanation: Only a subset of Dhall expressions can be converted to a directory \n\\
432+ \t ree. Specifically, record literals or maps can be converted to directories, \n\\
433+ \❰Text❱ literals can be converted to files, and ❰Optional❱ values are included if \n\\
434+ \❰Some❱ and omitted if ❰None❱. Values of union types can also be converted if \n\\
435+ \t hey are an alternative which has a non-nullary constructor whose argument is of \n\\
436+ \a n otherwise convertible type. Furthermore, there is a more advanced approach to \n\\
437+ \constructing a directory tree utilizing a fixpoint encoding. Consult the upstream \n\\
438+ \documentation of the `toDirectoryTree` function in the Dhall.Directory module for \n\\
439+ \f urther information on that. \n\\
440+ \No other type of value can be translated to a directory tree. \n\\
441+ \ \n\\
442+ \For example, this is a valid expression that can be translated to a directory \n\\
443+ \t ree: \n\\
444+ \ \n\\
445+ \ \n\\
446+ \ ┌──────────────────────────────────┐ \n\\
447+ \ │ { `example.json` = \" [1 , true]\ " } │ \n\\
448+ \ └──────────────────────────────────┘ \n\\
449+ \ \n\\
450+ \ \n\\
451+ \In contrast, the following expression is not allowed due to containing a \n\\
452+ \❰Natural❱ field, which cannot be translated in this way: \n\\
453+ \ \n\\
454+ \ \n\\
455+ \ ┌───────────────────────┐ \n\\
456+ \ │ { `example.txt` = 1 } │ \n\\
457+ \ └───────────────────────┘ \n\\
458+ \ \n\\
459+ \ \n\\
460+ \Note that key names cannot contain path separators: \n\\
461+ \ \n\\
462+ \ \n\\
463+ \ ┌─────────────────────────────────────┐ \n\\
464+ \ │ { `directory/example.txt` = \" ABC \ " } │ Invalid: Key contains a forward slash\n\\
465+ \ └─────────────────────────────────────┘ \n\\
466+ \ \n\\
467+ \ \n\\
468+ \Instead, you need to refactor the expression to use nested records instead: \n\\
469+ \ \n\\
470+ \ \n\\
471+ \ ┌───────────────────────────────────────────┐ \n\\
472+ \ │ { directory = { `example.txt` = \" ABC \ " } } │ \n\\
473+ \ └───────────────────────────────────────────┘ \n\\
474+ \ \n\\
475+ \ \n\\
476+ \You tried to translate the following expression to a directory tree: \n\\
477+ \ \n\\
478+ \" <> Util.insert unexpectedExpression <> " \ n\\
479+ \ \ n\\
463480 \... which is not an expression that can be translated to a directory tree. \ n"
464481
465482{- | This error indicates that you want to set some metadata for a file or
@@ -475,11 +492,11 @@ instance Show MetadataUnsupportedError where
475492 Pretty.renderString (Dhall.Pretty.layout message)
476493 where
477494 message =
478- Util. _ERROR <> " : Setting metadata is not supported on this platform. \n \
479- \ \n \
480- \Explanation: Your Dhall expression indicates that you intend to set some metadata \n \
481- \like ownership or permissions for the following file or directory: \n \
482- \ \n \
483- \" <> Pretty. pretty metadataForPath <> " \n \
484- \ \n \
495+ Util._ERROR <> " : Setting metadata is not supported on this platform. \ n\\
496+ \ \ n\\
497+ \ Explanation : Your Dhall expression indicates that you intend to set some metadata \ n\\
498+ \ like ownership or permissions for the following file or directory: \ n\\
499+ \ \ n\\
500+ \ " <> Pretty.pretty metadataForPath <> " \ n\\
501+ \ \ n\\
485502 \... which is not supported on your platform. \ n"
0 commit comments