e213ef310f
* Fix minor FD leak in journal code. Closes: #754608 * direct: Fix handling of case where a work tree subdirectory cannot be written to due to permissions. * migrate: Avoid re-checksumming when migrating from hashE to hash backend. * uninit: Avoid failing final removal in some direct mode repositories due to file modes. * S3: Deal with AWS ACL configurations that do not allow creating or checking the location of a bucket, but only reading and writing content to it. * resolvemerge: New plumbing command that runs the automatic merge conflict resolver. * Deal with change in git 2.0 that made indirect mode merge conflict resolution leave behind old files. * sync: Fix git sync with local git remotes even when they don't have an annex.uuid set. (The assistant already did so.) * Set gcrypt-publish-participants when setting up a gcrypt repository, to avoid unncessary passphrase prompts. This is a security/usability tradeoff. To avoid exposing the gpg key ids who can decrypt the repository, users can unset gcrypt-publish-participants. * Install nautilus hooks even when ~/.local/share/nautilus/ does not yet exist, since it is not automatically created for Gnome 3 users. * Windows: Move .vbs files out of git\bin, to avoid that being in the PATH, which caused some weird breakage. (Thanks, divB) * Windows: Fix locking issue that prevented the webapp starting (since 5.20140707). # imported from the archive
120 lines
3.1 KiB
Haskell
120 lines
3.1 KiB
Haskell
{- More control over touching a file.
|
|
-
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
-
|
|
- License: BSD-2-clause
|
|
-}
|
|
|
|
{-# LANGUAGE ForeignFunctionInterface #-}
|
|
|
|
module Utility.Touch (
|
|
TimeSpec(..),
|
|
touchBoth,
|
|
touch
|
|
) where
|
|
|
|
import Utility.FileSystemEncoding
|
|
|
|
import Foreign
|
|
import Foreign.C
|
|
import Control.Monad (when)
|
|
|
|
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 ()
|
|
touch file mtime = touchBoth file mtime mtime
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <sys/time.h>
|
|
|
|
#ifndef _BSD_SOURCE
|
|
#define _BSD_SOURCE
|
|
#endif
|
|
|
|
#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
|
|
|
|
instance Storable TimeSpec where
|
|
-- use the larger alignment of the two types in the struct
|
|
alignment _ = max sec_alignment nsec_alignment
|
|
where
|
|
sec_alignment = alignment (undefined::CTime)
|
|
nsec_alignment = alignment (undefined::CLong)
|
|
sizeOf _ = #{size struct timespec}
|
|
peek ptr = do
|
|
sec <- #{peek struct timespec, tv_sec} ptr
|
|
return $ TimeSpec sec
|
|
poke ptr (TimeSpec sec) = do
|
|
#{poke struct timespec, tv_sec} ptr sec
|
|
#{poke struct timespec, tv_nsec} ptr (0 :: CLong)
|
|
|
|
{- While its interface is beastly, utimensat is in recent
|
|
POSIX standards, unlike lutimes. -}
|
|
foreign import ccall "utimensat"
|
|
c_utimensat :: CInt -> CString -> Ptr TimeSpec -> CInt -> IO CInt
|
|
|
|
touchBoth file atime mtime follow =
|
|
allocaArray 2 $ \ptr ->
|
|
withFilePath file $ \f -> do
|
|
pokeArray ptr [atime, mtime]
|
|
r <- c_utimensat at_fdcwd f ptr flags
|
|
when (r /= 0) $ throwErrno "touchBoth"
|
|
where
|
|
flags
|
|
| follow = 0
|
|
| otherwise = at_symlink_nofollow
|
|
|
|
#else
|
|
#if 0
|
|
{- Using lutimes is needed for BSD.
|
|
-
|
|
- TODO: test if lutimes is available. May have to do it in configure.
|
|
- TODO: TimeSpec uses a CTime, while tv_sec is a CLong. It is implementation
|
|
- dependent whether these are the same; need to find a cast that works.
|
|
- (Without the cast it works on linux i386, but
|
|
- maybe not elsewhere.)
|
|
-}
|
|
|
|
instance Storable TimeSpec where
|
|
alignment _ = alignment (undefined::CLong)
|
|
sizeOf _ = #{size struct timeval}
|
|
peek ptr = do
|
|
sec <- #{peek struct timeval, tv_sec} ptr
|
|
return $ TimeSpec sec
|
|
poke ptr (TimeSpec sec) = do
|
|
#{poke struct timeval, tv_sec} ptr sec
|
|
#{poke struct timeval, tv_usec} ptr (0 :: CLong)
|
|
|
|
foreign import ccall "utimes"
|
|
c_utimes :: CString -> Ptr TimeSpec -> IO CInt
|
|
foreign import ccall "lutimes"
|
|
c_lutimes :: CString -> Ptr TimeSpec -> IO CInt
|
|
|
|
touchBoth file atime mtime follow =
|
|
allocaArray 2 $ \ptr ->
|
|
withFilePath file $ \f -> do
|
|
pokeArray ptr [atime, mtime]
|
|
r <- syscall f ptr
|
|
when (r /= 0) $
|
|
throwErrno "touchBoth"
|
|
where
|
|
syscall
|
|
| follow = c_lutimes
|
|
| otherwise = c_utimes
|
|
|
|
#else
|
|
#warning "utimensat and lutimes not available; building without symlink timestamp preservation support"
|
|
touchBoth _ _ _ _ = return ()
|
|
#endif
|
|
#endif
|