@@ -42,6 +42,7 @@ import System.FilePath ((</>))
42
42
import System.PosixCompat.Types (FileMode , GroupID , UserID )
43
43
44
44
import qualified Control.Exception as Exception
45
+ import qualified Data.ByteString as ByteString
45
46
import qualified Data.Foldable as Foldable
46
47
import qualified Data.Text as Text
47
48
import qualified Data.Text.IO as Text.IO
@@ -279,7 +280,7 @@ getUser (UserName name) =
279
280
-- | Resolve a `Group` to a numerical id.
280
281
getGroup :: Group -> IO GroupID
281
282
getGroup (GroupId gid) = return gid
282
- getGroup (GroupName name) =
283
+ getGroup (GroupName name) =
283
284
#ifdef mingw32_HOST_OS
284
285
ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
285
286
where x = " System.Posix.User.getGroupEntryForName: not supported"
@@ -290,21 +291,29 @@ getGroup (GroupName name) =
290
291
-- | Process a `FilesystemEntry`. Writes the content to disk and apply the
291
292
-- metadata to the newly created item.
292
293
processFilesystemEntry :: Bool -> FilePath -> FilesystemEntry -> IO ()
293
- processFilesystemEntry allowSeparators path (DirectoryEntry entry) = do
294
- let path' = path </> entryName entry
295
- when (hasMetadata entry && not isMetadataSupported) $
296
- Exception. throwIO $ MetadataUnsupportedError path'
297
- Directory. createDirectoryIfMissing allowSeparators path'
298
- processFilesystemEntryList allowSeparators path' $ entryContent entry
299
- -- It is important that we write the metadata after we wrote the content of
300
- -- the directories/files below this directory as we might lock ourself out
301
- -- by changing ownership or permissions.
302
- applyMetadata entry path'
303
- processFilesystemEntry _ path (FileEntry entry) = do
294
+ processFilesystemEntry allowSeparators path (DirectoryEntry entry) =
295
+ processEntryWith path entry $ \ path' content -> do
296
+ Directory. createDirectoryIfMissing allowSeparators path'
297
+ 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)
301
+ processFilesystemEntry _ path (BinaryFileEntry entry) =
302
+ processEntryWith path entry ByteString. writeFile
303
+ processFilesystemEntry _ path (TextFileEntry entry) =
304
+ processEntryWith path entry Text.IO. writeFile
305
+
306
+ -- | A helper function used by 'processFilesystemEntry'.
307
+ processEntryWith
308
+ :: FilePath
309
+ -> Entry a
310
+ -> (FilePath -> a -> IO () )
311
+ -> IO ()
312
+ processEntryWith path entry f = do
304
313
let path' = path </> entryName entry
305
314
when (hasMetadata entry && not isMetadataSupported) $
306
- Exception. throwIO $ MetadataUnsupportedError path'
307
- Text.IO. writeFile path' $ entryContent entry
315
+ Exception. throwIO ( MetadataUnsupportedError path')
316
+ f path' ( entryContent entry)
308
317
-- It is important that we write the metadata after we wrote the content of
309
318
-- the file as we might lock ourself out by changing ownership or
310
319
-- permissions.
0 commit comments