Symlink timestamp preservation code uses functions from unix-2.7.0 when available...
authorJoey Hess <joeyh@joeyh.name>
Wed, 21 Oct 2015 06:22:18 +0000 (02:22 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 21 Oct 2015 06:22:18 +0000 (02:22 -0400)
Utility/Touch.hsc
debian/changelog

index c3318e6da30d90dcb5788b275911f7dff7a962d7..e1b1e887e99a8da138b5020be23a8e4a03f7513a 100644 (file)
@@ -5,7 +5,7 @@
  - License: BSD-2-clause
  -}
 
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP #-}
 
 module Utility.Touch (
        TimeSpec(..),
@@ -13,6 +13,26 @@ module Utility.Touch (
        touch
 ) where
 
+#if MIN_VERSION_unix(2,7,0)
+
+import System.Posix.Files
+import System.Posix.Types
+
+newtype TimeSpec = TimeSpec EpochTime
+
+{- Changes the access and modification times of an existing file.
+   Can follow symlinks, or not. Throws IO error on failure. -}
+touchBoth :: FilePath -> TimeSpec -> TimeSpec -> Bool -> IO ()
+touchBoth file (TimeSpec atime) (TimeSpec mtime) follow
+       | follow = setFileTimes file atime mtime
+       | otherwise = setSymbolicLinkTimesHiRes file (realToFrac atime) (realToFrac mtime)
+
+touch :: FilePath -> TimeSpec -> Bool -> IO ()
+touch file mtime = touchBoth file mtime mtime
+
+#else
+{- Compatability interface for old version of unix, to be removed eventally. -}
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -35,8 +55,6 @@ import Foreign.C
 
 newtype TimeSpec = TimeSpec CTime
 
-{- Changes the access and modification times of an existing file.
-   Can follow symlinks, or not. Throws IO error on failure. -}
 touchBoth :: FilePath -> TimeSpec -> TimeSpec -> Bool -> IO ()
 
 touch :: FilePath -> TimeSpec -> Bool -> IO ()
@@ -123,3 +141,5 @@ touchBoth file atime mtime follow =
 touchBoth _ _ _ _ = return ()
 #endif
 #endif
+
+#endif
index 9d768ad28ccefd5715315656d8ce4a9050b4d096..2892424298f56b32aa8e78e100dfcb13d7e367cb 100644 (file)
@@ -1,6 +1,8 @@
 git-annex (5.20151020) UNRELEASED; urgency=medium
 
   * Use statvfs on OSX.
+  * Symlink timestamp preservation code uses functions
+    from unix-2.7.0 when available, which should be more portable.
 
  -- Joey Hess <id@joeyh.name>  Mon, 19 Oct 2015 17:00:21 -0400