Skip to content

Commit fb56888

Browse files
authored
DirectoryTree: Add binary-file to support creating files with Bytes content (#2641)
* DirectoryTree: Replaced `file` with `binary-file` and `text-file` * to-directory-tree: Revert the deprecation of `file` Instead, simply add `binary-file` such that we stay backwards compatible. * Linted to-directory-tree test files
1 parent 9c9ac87 commit fb56888

File tree

6 files changed

+47
-31
lines changed

6 files changed

+47
-31
lines changed

dhall/src/Dhall/DirectoryTree.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ directoryTreeType = Pi Nothing "tree" (Const Type)
259259
makeType :: Expector (Expr Src Void)
260260
makeType = Record . Map.fromList <$> sequenceA
261261
[ makeConstructor "directory" (Decode.auto :: Decoder DirectoryEntry)
262-
, makeConstructor "file" (Decode.auto :: Decoder FileEntry)
262+
, makeConstructor "file" (Decode.auto :: Decoder TextFileEntry)
263+
, makeConstructor "binary-file" (Decode.auto :: Decoder BinaryFileEntry)
263264
]
264265
where
265266
makeConstructor :: Text -> Decoder b -> Expector (Text, RecordField Src Void)
@@ -295,9 +296,6 @@ processFilesystemEntry allowSeparators path (DirectoryEntry entry) =
295296
processEntryWith path entry $ \path' content -> do
296297
Directory.createDirectoryIfMissing allowSeparators path'
297298
processFilesystemEntryList allowSeparators path' content
298-
processFilesystemEntry allowSeparators path (FileEntry entry) = do
299-
Util.printWarning "`file` is deprecated and will be removed eventually. Please use `text-file` instead."
300-
processFilesystemEntry allowSeparators path (TextFileEntry entry)
301299
processFilesystemEntry _ path (BinaryFileEntry entry) =
302300
processEntryWith path entry ByteString.writeFile
303301
processFilesystemEntry _ path (TextFileEntry entry) =

dhall/src/Dhall/DirectoryTree/Types.hs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
-- | Types used by the implementation of the @to-directory-tree@ subcommand
1414
module Dhall.DirectoryTree.Types
15-
( FilesystemEntry(..)
15+
( FilesystemEntry(DirectoryEntry, BinaryFileEntry, TextFileEntry, FileEntry)
1616
, DirectoryEntry
1717
, FileEntry
18+
, BinaryFileEntry
19+
, TextFileEntry
1820
, Entry(..)
1921
, User(..)
2022
, Group(..)
@@ -67,28 +69,35 @@ pattern Make label entry <- App (Field (Var (V "_" 0)) (fieldSelectionLabel -> l
6769
type DirectoryEntry = Entry (Seq FilesystemEntry)
6870

6971
-- | A file in the filesystem.
72+
{-# DEPRECATED FileEntry "`FileEntry` is deprecated and will be removed eventually. Please use `TextFileEntry` instead." #-}
7073
type FileEntry = Entry Text
7174

75+
-- | A binary file in the filesystem.
76+
type BinaryFileEntry = Entry ByteString
77+
78+
-- | A text file in the filesystem.
79+
type TextFileEntry = Entry Text
80+
7281
-- | A filesystem entry.
7382
data FilesystemEntry
7483
= DirectoryEntry (Entry (Seq FilesystemEntry))
75-
| FileEntry (Entry Text)
76-
| BinaryFileEntry (Entry ByteString)
77-
| TextFileEntry (Entry Text)
84+
| BinaryFileEntry BinaryFileEntry
85+
| TextFileEntry TextFileEntry
7886
deriving (Eq, Generic, Ord, Show)
7987

88+
pattern FileEntry :: Entry Text -> FilesystemEntry
89+
pattern FileEntry entry = TextFileEntry entry
90+
8091
instance FromDhall FilesystemEntry where
8192
autoWith normalizer = Decoder
8293
{ expected = pure $ Var (V "tree" 0)
8394
, extract = \case
8495
Make "directory" entry ->
8596
DirectoryEntry <$> extract (autoWith normalizer) entry
8697
Make "file" entry ->
87-
FileEntry <$> extract (autoWith normalizer) entry
98+
TextFileEntry <$> extract (autoWith normalizer) entry
8899
Make "binary-file" entry ->
89100
BinaryFileEntry <$> extract (autoWith normalizer) entry
90-
Make "text-file" entry ->
91-
TextFileEntry <$> extract (autoWith normalizer) entry
92101
expr -> Decode.typeError (expected (Decode.autoWith normalizer :: Decoder FilesystemEntry)) expr
93102
}
94103

dhall/tests/Dhall/Test/DirectoryTree.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ fixpointedUserGroup = testCase "user and group" $ do
8484
expr <- Dhall.inputExpr file
8585
entries <- decodeDirectoryTree expr
8686
entries @?=
87-
[ FileEntry $ Entry
87+
[ TextFileEntry $ Entry
8888
{ entryName = "ids"
8989
, entryContent = ""
9090
, entryUser = Just (UserId 0)
9191
, entryGroup = Just (GroupId 0)
9292
, entryMode = Nothing
9393
}
94-
, FileEntry $ Entry
94+
, TextFileEntry $ Entry
9595
{ entryName = "names"
9696
, entryContent = ""
9797
, entryUser = Just (UserName "user")

dhall/tests/to-directory-tree/fixpoint-helper.dhall

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ let Entry =
2121
}
2222

2323
let Make =
24-
\(r : Type) -> { directory : Entry (List r) -> r, file : Entry Text -> r }
24+
\(r : Type) ->
25+
{ directory : Entry (List r) -> r
26+
, binary-file : Entry Bytes -> r
27+
, file : Entry Text -> r
28+
}
2529

2630
in { User, Group, Access, Mode, Entry, Make }

dhall/tests/to-directory-tree/fixpoint-simple.dhall

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ let Make = (./fixpoint-helper.dhall).Make
88

99
in \(r : Type) ->
1010
\(make : Make r) ->
11-
[ make.file
12-
{ name = "file"
13-
, content = ""
14-
, user = None User
15-
, group = None Group
16-
, mode = None Mode
17-
}
18-
, make.directory
19-
{ name = "directory"
20-
, content = [] : List r
21-
, user = None User
22-
, group = None Group
23-
, mode = None Mode
24-
}
25-
]
11+
[ make.file
12+
{ name = "file"
13+
, content = ""
14+
, user = None User
15+
, group = None Group
16+
, mode = None Mode
17+
}
18+
, make.directory
19+
{ name = "directory"
20+
, content = [] : List r
21+
, user = None User
22+
, group = None Group
23+
, mode = None Mode
24+
}
25+
]

dhall/tests/to-directory-tree/type.dhall

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ let Entry =
2323
in forall (result : Type) ->
2424
let DirectoryEntry = Entry (List result)
2525

26-
let FileEntry = Entry Text
26+
let BinaryFileEntry = Entry Bytes
27+
28+
let TextFileEntry = Entry Text
2729

2830
let Make =
29-
{ directory : DirectoryEntry -> result, file : FileEntry -> result }
31+
{ directory : DirectoryEntry -> result
32+
, binary-file : BinaryFileEntry -> result
33+
, file : TextFileEntry -> result
34+
}
3035

3136
in forall (make : Make) -> List result

0 commit comments

Comments
 (0)