Skip to content

Commit

Permalink
Fix build on Darwin
Browse files Browse the repository at this point in the history
There were a number of issues there, largely due to the fact that this
codepath is CPP-guarded.
  • Loading branch information
bgamari committed Apr 17, 2016
1 parent 74e5058 commit e16b2c1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ import Data.Maybe
( catMaybes
#ifdef mingw32_HOST_OS
, maybeToList
#endif
#if !defined(mingw32_HOST_OS) && ! defined(HAVE_UTIMENSAT)
, fromMaybe
#endif
)

Expand All @@ -133,9 +136,7 @@ import Data.Time ( UTCTime )
import Data.Time.Clock.POSIX
( posixSecondsToUTCTime
, utcTimeToPOSIXSeconds
#ifdef mingw32_HOST_OS
, POSIXTime
#endif
)

import GHC.IO.Exception ( IOErrorType(InappropriateType) )
Expand Down Expand Up @@ -1524,6 +1525,8 @@ setFileTimes path (atime, mtime) =
setTimes (utcTimeToPOSIXSeconds <$> atime, utcTimeToPOSIXSeconds <$> mtime)
where
path' = normalise path -- handle empty paths

setTimes :: (Maybe POSIXTime, Maybe POSIXTime) -> IO ()
#ifdef mingw32_HOST_OS
setTimes (atime', mtime') =
bracket (openFileHandle path' Win32.gENERIC_WRITE)
Expand All @@ -1540,16 +1543,18 @@ setFileTimes path (atime, mtime) =
throwErrnoPathIfMinus1_ "" path' $
c_utimensat c_AT_FDCWD path'' times 0
#else
setTimes (Just atime', Just mtime') = setFileTimes path' atime' mtime'
setTimes (Just atime', Just mtime') = setFileTimes' path' atime' mtime'
setTimes (atime', mtime') = do
(atimeOld, mtimeOld) <- fileTimesFromStatus <$> Posix.getFileStatus path'
setFileTimes path'
(fromMaybe atimeOld atime')
(fromMaybe mtimeOld mtime')
setFileTimes' path'
(fromMaybe (utcTimeToPOSIXSeconds atimeOld) atime')
(fromMaybe (utcTimeToPOSIXSeconds mtimeOld) mtime')

setFileTimes' :: FilePath -> POSIXTime -> POSIXTime -> IO ()
# if MIN_VERSION_unix(2, 7, 0)
setFileTimes = Posix.setFileTimesHiRes
setFileTimes' = Posix.setFileTimesHiRes
# else
setFileTimes pth atim mtime =
setFileTimes' pth atim mtime =
Posix.setFileTimes pth
(fromInteger (truncate atime))
(fromInteger (truncate mtime))
Expand Down

0 comments on commit e16b2c1

Please sign in to comment.