@@ -42,6 +42,7 @@ import System.FilePath ((</>))
4242import System.PosixCompat.Types (FileMode , GroupID , UserID )
4343
4444import qualified Control.Exception as Exception
45+ import qualified Data.ByteString as ByteString
4546import qualified Data.Foldable as Foldable
4647import qualified Data.Text as Text
4748import qualified Data.Text.IO as Text.IO
@@ -279,7 +280,7 @@ getUser (UserName name) =
279280-- | Resolve a `Group` to a numerical id.
280281getGroup :: Group -> IO GroupID
281282getGroup (GroupId gid) = return gid
282- getGroup (GroupName name) =
283+ getGroup (GroupName name) =
283284#ifdef mingw32_HOST_OS
284285 ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
285286 where x = " System.Posix.User.getGroupEntryForName: not supported"
@@ -290,21 +291,29 @@ getGroup (GroupName name) =
290291-- | Process a `FilesystemEntry`. Writes the content to disk and apply the
291292-- metadata to the newly created item.
292293processFilesystemEntry :: 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
304313 let path' = path </> entryName entry
305314 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)
308317 -- It is important that we write the metadata after we wrote the content of
309318 -- the file as we might lock ourself out by changing ownership or
310319 -- permissions.
0 commit comments