1
0
forked from GitHub/gf-rgl

Copy files with only modification time rather than all metadata

This commit is contained in:
John J. Camilleri
2018-10-26 09:10:32 +02:00
parent 4ee5914c1c
commit 999cdb8e36

16
Make.hs
View File

@@ -1,3 +1,7 @@
-- | Main build script for RGL
-- There is no associated cabal file, but these dependencies are known:
-- * directory >= 1.2.3.0
import Data.List (find,isPrefixOf,isSuffixOf,(\\),unfoldr)
import Data.Maybe (catMaybes)
import System.IO (hPutStrLn,stderr)
@@ -6,7 +10,7 @@ import System.Exit (ExitCode(..),die)
import System.Environment (getArgs,lookupEnv)
import System.Process (rawSystem)
import System.FilePath ((</>)) -- ,takeFileName,addExtension,dropExtension)
import System.Directory (createDirectoryIfMissing,copyFileWithMetadata,getDirectoryContents,removeDirectoryRecursive,findFile)
import System.Directory (createDirectoryIfMissing,copyFile,getModificationTime,setModificationTime,getDirectoryContents,removeDirectoryRecursive,findFile)
import Control.Monad (when,unless)
main :: IO ()
@@ -61,14 +65,20 @@ copyOne :: String -> FilePath -> FilePath -> IO ()
copyOne file from to = do
putStrLn $ "Copying [" ++ file ++ "] " ++ to
createDirectoryIfMissing True to
copyFileWithMetadata (from </> file) (to </> file)
copyFileWithModificationTime (from </> file) (to </> file)
-- | Copy all files between directories
copyAll :: String -> FilePath -> FilePath -> IO ()
copyAll msg from to = do
putStrLn $ "Copying [" ++ msg ++ "] " ++ to
createDirectoryIfMissing True to
mapM_ (\file -> when (file /= "." && file /= "..") $ copyFileWithMetadata (from </> file) (to </> file)) =<< getDirectoryContents from
mapM_ (\file -> when (file /= "." && file /= "..") $ copyFileWithModificationTime (from </> file) (to </> file)) =<< getDirectoryContents from
-- | Copy a file together with its modification time but no other meta data
copyFileWithModificationTime :: FilePath -> FilePath -> IO ()
copyFileWithModificationTime source destination = do
copyFile source destination
getModificationTime source >>= setModificationTime destination
-- | Remove dist directory
clean :: IO ()