Skip to content

Commit

Permalink
to-directory-tree: Revert the deprecation of file
Browse files Browse the repository at this point in the history
Instead, simply add `binary-file` such that we stay backwards
compatible.
  • Loading branch information
mmhat committed Feb 13, 2025
1 parent fbcbc95 commit 170dd9b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
6 changes: 1 addition & 5 deletions dhall/src/Dhall/DirectoryTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Implementation of the @dhall to-directory-tree@ subcommand
Expand Down Expand Up @@ -260,8 +259,8 @@ directoryTreeType = Pi Nothing "tree" (Const Type)
makeType :: Expector (Expr Src Void)
makeType = Record . Map.fromList <$> sequenceA
[ makeConstructor "directory" (Decode.auto :: Decoder DirectoryEntry)
, makeConstructor "file" (Decode.auto :: Decoder TextFileEntry)
, makeConstructor "binary-file" (Decode.auto :: Decoder BinaryFileEntry)
, makeConstructor "text-file" (Decode.auto :: Decoder TextFileEntry)
]
where
makeConstructor :: Text -> Decoder b -> Expector (Text, RecordField Src Void)
Expand Down Expand Up @@ -297,9 +296,6 @@ processFilesystemEntry allowSeparators path (DirectoryEntry entry) =
processEntryWith path entry $ \path' content -> do
Directory.createDirectoryIfMissing allowSeparators path'
processFilesystemEntryList allowSeparators path' content
processFilesystemEntry allowSeparators path (FileEntry entry) = do
Util.printWarning "`file` is deprecated and will be removed eventually. Please use `text-file` instead."
processFilesystemEntry allowSeparators path (TextFileEntry entry)
processFilesystemEntry _ path (BinaryFileEntry entry) =
processEntryWith path entry ByteString.writeFile
processFilesystemEntry _ path (TextFileEntry entry) =
Expand Down
10 changes: 6 additions & 4 deletions dhall/src/Dhall/DirectoryTree/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

-- | Types used by the implementation of the @to-directory-tree@ subcommand
module Dhall.DirectoryTree.Types
( FilesystemEntry(..)
( FilesystemEntry(DirectoryEntry, BinaryFileEntry, TextFileEntry, FileEntry)
, DirectoryEntry
, FileEntry
, BinaryFileEntry
Expand Down Expand Up @@ -81,21 +81,23 @@ type TextFileEntry = Entry Text
-- | A filesystem entry.
data FilesystemEntry
= DirectoryEntry (Entry (Seq FilesystemEntry))
| FileEntry (Entry Text)
| BinaryFileEntry BinaryFileEntry
| TextFileEntry TextFileEntry
deriving (Eq, Generic, Ord, Show)

pattern FileEntry :: Entry Text -> FilesystemEntry
pattern FileEntry entry = TextFileEntry entry

instance FromDhall FilesystemEntry where
autoWith normalizer = Decoder
{ expected = pure $ Var (V "tree" 0)
, extract = \case
Make "directory" entry ->
DirectoryEntry <$> extract (autoWith normalizer) entry
Make "file" entry ->
TextFileEntry <$> extract (autoWith normalizer) entry
Make "binary-file" entry ->
BinaryFileEntry <$> extract (autoWith normalizer) entry
Make "text-file" entry ->
TextFileEntry <$> extract (autoWith normalizer) entry
expr -> Decode.typeError (expected (Decode.autoWith normalizer :: Decoder FilesystemEntry)) expr
}

Expand Down
2 changes: 1 addition & 1 deletion dhall/tests/to-directory-tree/fixpoint-helper.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ let Entry =
}

let Make =
\(r : Type) -> { directory : Entry (List r) -> r, binary-file : Entry Bytes -> r, text-file : Entry Text -> r }
\(r : Type) -> { directory : Entry (List r) -> r, binary-file : Entry Bytes -> r, file : Entry Text -> r }

in { User, Group, Access, Mode, Entry, Make }
2 changes: 1 addition & 1 deletion dhall/tests/to-directory-tree/fixpoint-permissions.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let full-access = { execute = Some True, read = Some True, write = Some True }

in \(r : Type) ->
\(make : Make r) ->
[ make.text-file
[ make.file
{ name = "file"
, content = ""
, user = None User
Expand Down
2 changes: 1 addition & 1 deletion dhall/tests/to-directory-tree/fixpoint-simple.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let Make = (./fixpoint-helper.dhall).Make

in \(r : Type) ->
\(make : Make r) ->
[ make.text-file
[ make.file
{ name = "file"
, content = ""
, user = None User
Expand Down
4 changes: 2 additions & 2 deletions dhall/tests/to-directory-tree/fixpoint-usergroup.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ let Make = (./fixpoint-helper.dhall).Make

in \(r : Type) ->
\(make : Make r) ->
[ make.text-file
[ make.file
{ name = "ids"
, content = ""
, user = Some (User.UserId 0)
, group = Some (Group.GroupId 0)
, mode = None Mode
}
, make.text-file
, make.file
{ name = "names"
, content = ""
, user = Some (User.UserName "user")
Expand Down
4 changes: 2 additions & 2 deletions dhall/tests/to-directory-tree/type.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ let Entry =
, mode : Optional Mode
}

in forall (result : Type) ->
in forall (result : Type) ->
let DirectoryEntry = Entry (List result)

let BinaryFileEntry = Entry Bytes

let TextFileEntry = Entry Text

let Make =
{ directory : DirectoryEntry -> result, binary-file : BinaryFileEntry -> result, text-file : TextFileEntry -> result }
{ directory : DirectoryEntry -> result, binary-file : BinaryFileEntry -> result, file : TextFileEntry -> result }

in forall (make : Make) -> List result

0 comments on commit 170dd9b

Please sign in to comment.