#7473: getModificationTime gives only second-level resolution
-----------------------------+----------------------------------------------
Reporter:  duncan            |          Owner:                     
    Type:  bug               |         Status:  new                
Priority:  normal            |      Component:  libraries/directory
 Version:  7.6.1             |       Keywords:                     
      Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple   
 Failure:  None/Unknown      |      Blockedby:                     
Blocking:                    |        Related:                     
-----------------------------+----------------------------------------------
 The `System.Directory.getModificationTime` function only returns time with
 second-level granularity. This is no good for applications like `ghc
 --make` where we need to compare file timestamps.

 The fix should be simple, here's a patch (compiles but not tested) that
 should fix it for Unix, for Windows we will need a different fix, probably
 using the Win32 API directly, rather than the mingw C api.
 {{{
 diff --git a/System/Directory.hs b/System/Directory.hs
 index cfe7cd9..f27bfc4 100644
 --- a/System/Directory.hs
 +++ b/System/Directory.hs
 @@ -995,14 +995,14 @@ The operation may fail with:
  getModificationTime :: FilePath -> IO UTCTime
  getModificationTime name = do
  #ifdef mingw32_HOST_OS
 - -- ToDo: use Win32 API
 + -- ToDo: use Win32 API so we can get sub-second resolution
   withFileStatus "getModificationTime" name $ \ st -> do
   modificationTime st
  #else
    stat <- Posix.getFileStatus name
 -  let mod_time :: Posix.EpochTime
 -      mod_time = Posix.modificationTime stat
 -  return $ posixSecondsToUTCTime $ realToFrac mod_time
 +  let mod_time :: POSIXTime
 +      mod_time = Posix.modificationTimeHiRes stat
 +  return $! posixSecondsToUTCTime mod_time
  #endif

  #endif /* __GLASGOW_HASKELL__ */
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7473>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to