2018-10-30 02:22:36 +00:00
|
|
|
{- Portability shim for touching a file.
|
2016-02-15 15:47:33 +00:00
|
|
|
-
|
2018-10-30 02:22:36 +00:00
|
|
|
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
2016-02-15 15:47:33 +00:00
|
|
|
-
|
|
|
|
- License: BSD-2-clause
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Utility.Touch (
|
|
|
|
touchBoth,
|
|
|
|
touch
|
|
|
|
) where
|
|
|
|
|
2018-10-13 05:36:06 +00:00
|
|
|
#if ! defined(mingw32_HOST_OS)
|
2016-02-15 15:47:33 +00:00
|
|
|
|
|
|
|
import System.Posix.Files
|
2018-10-30 02:22:36 +00:00
|
|
|
import Data.Time.Clock.POSIX
|
2016-02-15 15:47:33 +00:00
|
|
|
|
|
|
|
{- Changes the access and modification times of an existing file.
|
2018-10-30 02:22:36 +00:00
|
|
|
Can follow symlinks, or not. -}
|
|
|
|
touchBoth :: FilePath -> POSIXTime -> POSIXTime -> Bool -> IO ()
|
|
|
|
touchBoth file atime mtime follow
|
|
|
|
| follow = setFileTimesHiRes file atime mtime
|
|
|
|
| otherwise = setSymbolicLinkTimesHiRes file atime mtime
|
|
|
|
|
|
|
|
{- Changes the access and modification times of an existing file
|
|
|
|
- to the same value. Can follow symlinks, or not. -}
|
|
|
|
touch :: FilePath -> POSIXTime -> Bool -> IO ()
|
2016-02-15 15:47:33 +00:00
|
|
|
touch file mtime = touchBoth file mtime mtime
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2018-10-30 02:22:36 +00:00
|
|
|
import Data.Time.Clock.POSIX
|
2016-02-15 15:47:33 +00:00
|
|
|
|
|
|
|
{- Noop for Windows -}
|
2018-10-30 02:22:36 +00:00
|
|
|
touchBoth :: FilePath -> POSIXTime -> POSIXTime -> Bool -> IO ()
|
2016-02-15 15:47:33 +00:00
|
|
|
touchBoth _ _ _ _ = return ()
|
|
|
|
|
2018-10-30 15:09:45 +00:00
|
|
|
touch :: FilePath -> POSIXTime -> Bool -> IO ()
|
2016-03-05 19:08:37 +00:00
|
|
|
touch _ _ _ = return ()
|
2016-02-15 15:47:33 +00:00
|
|
|
|
|
|
|
#endif
|