From 35cbd107d5107eb96f52860098b1036c73281715 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 16 Mar 2011 13:46:08 -0400 Subject: [PATCH] detect systems w/o utmensat and ifdef out code that needs it --- Touch.hsc | 37 +++++++++++++++++++++++++------------ debian/changelog | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Touch.hsc b/Touch.hsc index f0c4debb33..456175182e 100644 --- a/Touch.hsc +++ b/Touch.hsc @@ -28,6 +28,25 @@ import Foreign.C data TimeSpec = TimeSpec CTime CLong +touch :: FilePath -> TimeSpec -> Bool -> IO () +touch file mtime follow = touchBoth file omitTime mtime follow + +touchBoth :: FilePath -> TimeSpec -> TimeSpec -> Bool -> IO () + +omitTime :: TimeSpec +nowTime :: TimeSpec + +#if (defined UTIME_OMIT && defined UTIME_NOW && defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW) + +at_fdcwd :: CInt +at_fdcwd = #const AT_FDCWD + +at_symlink_nofollow :: CInt +at_symlink_nofollow = #const AT_SYMLINK_NOFOLLOW + +omitTime = TimeSpec 0 #const UTIME_OMIT +nowTime = TimeSpec 0 #const UTIME_NOW + instance Storable TimeSpec where -- use the larger alignment of the two types in the struct alignment _ = max sec_alignment nsec_alignment @@ -43,12 +62,6 @@ instance Storable TimeSpec where #{poke struct timespec, tv_sec} ptr sec #{poke struct timespec, tv_nsec} ptr nsec -{- special timespecs -} -omitTime :: TimeSpec -omitTime = TimeSpec 0 #const UTIME_OMIT -nowTime :: TimeSpec -nowTime = TimeSpec 0 #const UTIME_NOW - {- While its interface is beastly, utimensat is in recent POSIX standards, unlike futimes. -} foreign import ccall "utimensat" @@ -56,7 +69,6 @@ foreign import ccall "utimensat" {- Changes the access and/or modification times of an existing file. Can follow symlinks, or not. Throws IO error on failure. -} -touchBoth :: FilePath -> TimeSpec -> TimeSpec -> Bool -> IO () touchBoth file atime mtime follow = allocaArray 2 $ \ptr -> withCString file $ \f -> do @@ -66,12 +78,13 @@ touchBoth file atime mtime follow = then throwErrno "touchBoth" else return () where - at_fdcwd = #const AT_FDCWD - at_symlink_nofollow = #const AT_SYMLINK_NOFOLLOW - flags = if follow then 0 else at_symlink_nofollow -touch :: FilePath -> TimeSpec -> Bool -> IO () -touch file mtime follow = touchBoth file omitTime mtime follow +#else +#warning "utimensat not available; building without symlink timestamp preservation support" +omitTime = TimeSpec 0 (-1) +nowTime = TimeSpec 0 (-2) +touchBoth _ _ _ _ = return () +#endif diff --git a/debian/changelog b/debian/changelog index e7017a26d0..110fc2b4c0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ git-annex (0.24) UNRELEASED; urgency=low content are made to have the same mtime as the original file. While git does not preserve that information, this allows a tool like metastore to be used with annexed files. + (Currently this is only done on systems supporting POSIX 200809.) -- Joey Hess Sun, 13 Mar 2011 14:25:17 -0400