Skip to content
Browse files

Support directory 1.2

This also involves a conditional migration to the new "time" package
  • Loading branch information...
1 parent 2227910 commit eee53ea39478f271e0ede7fffcc43ea89fb053fc @hsenag hsenag committed
Showing with 75 additions and 15 deletions.
  1. +6 −6 src/System/PosixCompat/Files.hsc
  2. +46 −0 src/System/PosixCompat/Internal/Time.hs
  3. +4 −4 src/System/PosixCompat/Time.hs
  4. +19 −5 unix-compat.cabal
View
12 src/System/PosixCompat/Files.hsc
@@ -124,7 +124,11 @@ import System.Directory
import System.IO (IOMode(..), openFile, hFileSize, hSetFileSize, hClose)
import System.IO.Error
import System.PosixCompat.Types
-import System.Time (ClockTime(..), getClockTime)
+
+import System.PosixCompat.Internal.Time (
+ getClockTime, clockTimeToEpochTime
+ , modificationTimeToEpochTime
+ )
#ifdef __GLASGOW_HASKELL__
import GHC.IO.Handle.FD (fdToHandle)
@@ -297,7 +301,7 @@ getFileStatus path =
do perm <- liftM permsToMode $ getPermissions path
typ <- getFileType path
size <- if typ == regularFileMode then getFileSize path else return 0
- mtime <- liftM clockTimeToEpochTime $ getModificationTime path
+ mtime <- liftM modificationTimeToEpochTime $ getModificationTime path
return $ FileStatus
{ deviceID = -1
, fileID = -1
@@ -333,10 +337,6 @@ getFileSize :: FilePath -> IO FileOffset
getFileSize path =
bracket (openFile path ReadMode) hClose (liftM fromIntegral . hFileSize)
-clockTimeToEpochTime :: ClockTime -> EpochTime
-clockTimeToEpochTime (TOD s _) = fromInteger s
-
-
getFdStatus :: Fd -> IO FileStatus
getFdStatus _ = unsupported "getFdStatus"
View
46 src/System/PosixCompat/Internal/Time.hs
@@ -0,0 +1,46 @@
+{-# LANGUAGE CPP #-}
+{-
+Compatibility wrapper to help manage the transition from
+old-time to time packages. Only used at all on win32.
+-}
+module System.PosixCompat.Internal.Time (
+ ClockTime
+ , getClockTime
+ , clockTimeToEpochTime
+ , ModificationTime
+ , modificationTimeToEpochTime
+ ) where
+
+import System.Posix.Types (EpochTime)
+
+#ifdef OLD_TIME
+
+import System.Time (ClockTime(TOD), getClockTime)
+
+clockTimeToEpochTime :: ClockTime -> EpochTime
+clockTimeToEpochTime (TOD s _) = fromInteger s
+
+type ModificationTime = ClockTime
+
+modificationTimeToEpochTime :: ModificationTime -> EpochTime
+modificationTimeToEpochTime = clockTimeToEpochTime
+
+#else
+
+import Data.Time.Clock (UTCTime)
+import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime, utcTimeToPOSIXSeconds)
+
+type ClockTime = POSIXTime
+
+getClockTime :: IO ClockTime
+getClockTime = getPOSIXTime
+
+clockTimeToEpochTime :: ClockTime -> EpochTime
+clockTimeToEpochTime = fromInteger . floor
+
+type ModificationTime = UTCTime
+
+modificationTimeToEpochTime :: UTCTime -> EpochTime
+modificationTimeToEpochTime = clockTimeToEpochTime . utcTimeToPOSIXSeconds
+
+#endif
View
8 src/System/PosixCompat/Time.hs
@@ -18,7 +18,10 @@ import System.Posix.Time
import Control.Monad (liftM)
import System.Posix.Types (EpochTime)
-import System.Time (ClockTime(..), getClockTime)
+
+import System.PosixCompat.Internal.Time (
+ getClockTime, clockTimeToEpochTime
+ )
-- | The portable version of @epochTime@ calls 'getClockTime' to obtain the
-- number of seconds that have elapsed since the epoch (Jan 01 00:00:00 GMT
@@ -26,8 +29,5 @@ import System.Time (ClockTime(..), getClockTime)
epochTime :: IO EpochTime
epochTime = liftM clockTimeToEpochTime getClockTime
-clockTimeToEpochTime :: ClockTime -> EpochTime
-clockTimeToEpochTime (TOD s _) = fromInteger s
-
#endif
View
24 unix-compat.cabal
@@ -19,6 +19,10 @@ source-repository head
type: git
location: git://github.com/jystic/unix-compat.git
+flag old-time
+ description: build against old-time package
+ default: False
+
Library
hs-source-dirs: src
ghc-options: -Wall
@@ -35,16 +39,26 @@ Library
System.PosixCompat.User
if os(windows)
- build-depends: old-time >= 1.0.0.0 && < 1.2.0.0
c-sources:
cbits/HsUname.c
cbits/mktemp.c
- if impl(ghc < 7)
- build-depends: directory == 1.0.*
- cpp-options: -DDIRECTORY_1_0
+ if flag(old-time)
+ build-depends: old-time >= 1.0.0.0 && < 1.2.0.0
+ cpp-options: -DOLD_TIME
+
+ if impl(ghc < 7)
+ build-depends: directory == 1.0.*
+ cpp-options: -DDIRECTORY_1_0
+ else
+ build-depends: directory == 1.1.*
else
- build-depends: directory == 1.1.*
+ build-depends: time >= 1.0 && < 1.5
+ build-depends: directory >= 1.2 && < 1.3
+
+ other-modules:
+ System.PosixCompat.Internal.Time
+
else
build-depends: unix >= 2.4 && < 2.7
include-dirs: include

0 comments on commit eee53ea

Please sign in to comment.
Something went wrong with that request. Please try again.