Commit 7191c81d authored by Kristof Korwisi's avatar Kristof Korwisi
Browse files

Merge branch '81-native-haskell-copy' into 'master'

Resolve "Use native Haskell copy"

Closes #81

See merge request decker/decker!41
parents 32a8c602 cb4c8bda
......@@ -92,7 +92,7 @@ main = do
need ["watch"]
runHttpServer serverPort directories Nothing
--
phony "example" writeExampleProject
phony "example" $ liftIO writeExampleProject
--
phony "index" $ need ["support", index]
--
......@@ -203,10 +203,10 @@ main = do
(directories ^. support)
Just value
| value == show Copy ->
rsync
[ ((directories ^. appData) </> "support/")
, (directories ^. support)
]
liftIO $
copyDir
((directories ^. appData) </> "support")
(directories ^. support)
Nothing ->
liftIO $
createFileLink
......
......@@ -3,7 +3,8 @@ module Resources
( extractResources
, getResourceString
, deckerResourceDir
, writeResourceFiles
, writeExampleProject
, copyDir
) where
import Common
......@@ -53,9 +54,42 @@ unzip args = do
ExitFailure 1 -> True
_ -> False
-- | Write the example project to the current folder
writeExampleProject :: IO ()
writeExampleProject = writeResourceFiles "example" "."
writeResourceFiles :: FilePath -> FilePath -> IO ()
writeResourceFiles prefix destDir = do
dataDir <- deckerResourceDir
let src = dataDir </> prefix
exists <- doesDirectoryExist (destDir </> prefix)
unless exists $ callProcess "cp" ["-R", src, destDir]
copyDir src destDir
-- | Copy a file to a file location or to a directory
cp :: FilePath -> FilePath -> IO ()
cp src dst = do
unlessM (doesFileExist src) $
throw (userError "src does not exist or is not a file")
unlessM (doesFileExist dst) $ do
destIsDir <- doesDirectoryExist dst
if destIsDir
then copyFile src (dst </> takeFileName src)
else copyFile src dst
-- | Copy a directory and its contents recursively
copyDir :: FilePath -> FilePath -> IO ()
copyDir src dst = do
unlessM (doesDirectoryExist src) $
throw (userError "src does not exist or is not a directory")
dstExists <- doesDirectoryExist dst
if dstExists && (last (splitPath src) /= last (splitPath dst))
then copyDir src (dst </> last (splitPath src))
else do
createDirectoryIfMissing True dst
contents <- listDirectory src
forM_ contents $ \name -> do
let srcPath = src </> name
let dstPath = dst </> name
isDirectory <- doesDirectoryExist srcPath
if isDirectory
then copyDir srcPath dstPath
else cp srcPath dstPath
......@@ -10,7 +10,6 @@ module Utilities
, markdownToPdfHandout
, markdownToHtmlPage
, markdownToPdfPage
, writeExampleProject
, metaValueAsString
, (<++>)
, writeEmbeddedFiles
......@@ -675,8 +674,9 @@ processCitesWithDefault pandoc@(Pandoc meta blocks) =
_ -> return pandoc
liftIO $ processCites' document
writeExampleProject :: Action ()
writeExampleProject = liftIO $ writeResourceFiles "example" "."
-- moved to Resources.hs
-- writeExampleProject :: Action ()
-- writeExampleProject = liftIO $ writeResourceFiles "example" "."
{--
writeExampleProject :: Action ()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment