Skip to content

Commit

Permalink
Fixes #187 - copying files from ext that do not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
matijaSos committed Feb 22, 2021
1 parent 19bba53 commit 4e4d3cd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion waspc/src/Generator/FileDraft/WriteableMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Generator.FileDraft.WriteableMonad

import qualified System.Directory
import qualified Data.Text.IO
import Control.Exception (try, SomeException)
import Data.Aeson as Aeson
import Data.Text (Text)

Expand Down Expand Up @@ -48,7 +49,20 @@ class (Monad m) => WriteableMonad m where

instance WriteableMonad IO where
createDirectoryIfMissing = System.Directory.createDirectoryIfMissing
copyFile = System.Directory.copyFile

-- NOTE(matija): this is the short version, not very nice?
--copyFile src dst = ((try (System.Directory.copyFile src dst)) :: IO (Either SomeException ())) >> return ()

copyFile src dst = do
-- NOTE(matija): we had cases (e.g. tmp Vim files) where a file initially existed
-- when the filedraft was created but then got deleted before actual copying was invoked.
-- That would make this function crash, so here we ignore

-- TODO(matija): we are currently fetching all the exceptions, which is not ideal. I tried IOException
-- but it wasn't the right exception type.
(_ :: Either SomeException a) <- try (System.Directory.copyFile src dst)
return ()

writeFileFromText = Data.Text.IO.writeFile
getTemplateFileAbsPath = Templates.getTemplateFileAbsPath
getTemplatesDirAbsPath = Templates.getTemplatesDirAbsPath
Expand Down

0 comments on commit 4e4d3cd

Please sign in to comment.