@@ -37,16 +37,17 @@ import Data.Maybe
37
37
import qualified Data.Rope.UTF16 as Rope
38
38
import qualified Data.Text as T
39
39
import Data.Time
40
+ import Data.Time.Clock.POSIX
40
41
import Development.IDE.Core.OfInterest (OfInterestVar (.. ),
41
42
getFilesOfInterest )
42
43
import Development.IDE.Core.RuleTypes
43
44
import Development.IDE.Core.Shake
44
45
import Development.IDE.GHC.Orphans ()
46
+ import Development.IDE.Graph
45
47
import Development.IDE.Import.DependencyInformation
46
48
import Development.IDE.Types.Diagnostics
47
49
import Development.IDE.Types.Location
48
50
import Development.IDE.Types.Options
49
- import Development.IDE.Graph
50
51
import HieDb.Create (deleteMissingRealFiles )
51
52
import Ide.Plugin.Config (CheckParents (.. ))
52
53
import System.IO.Error
@@ -62,6 +63,7 @@ import Foreign.Marshal (alloca)
62
63
import Foreign.Ptr
63
64
import Foreign.Storable
64
65
import qualified System.Posix.Error as Posix
66
+ import System.Posix.Files (getFileStatus , modificationTimeHiRes )
65
67
#endif
66
68
67
69
import qualified Development.IDE.Types.Logger as L
@@ -126,7 +128,7 @@ getModificationTimeImpl :: VFSHandle
126
128
(Maybe BS. ByteString , ([FileDiagnostic ], Maybe FileVersion ))
127
129
getModificationTimeImpl vfs isWatched missingFileDiags file = do
128
130
let file' = fromNormalizedFilePath file
129
- let wrap time@ (l,s) = (Just $ LBS. toStrict $ B. encode time, ([] , Just $ ModificationTime l s ))
131
+ let wrap time = (Just $ LBS. toStrict $ B. encode $ toRational time, ([] , Just $ ModificationTime time ))
130
132
mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file
131
133
case mbVirtual of
132
134
Just (virtualFileVersion -> ver) -> do
@@ -192,38 +194,17 @@ resetFileStore ideState changes = mask $ \_ ->
192
194
-- We might also want to try speeding this up on Windows at some point.
193
195
-- TODO leverage DidChangeWatchedFile lsp notifications on clients that
194
196
-- support them, as done for GetFileExists
195
- getModTime :: FilePath -> IO ( Int64 , Int64 )
197
+ getModTime :: FilePath -> IO POSIXTime
196
198
getModTime f =
197
199
#ifdef mingw32_HOST_OS
198
- do time <- Dir. getModificationTime f
199
- let ! day = fromInteger $ toModifiedJulianDay $ utctDay time
200
- ! dayTime = fromInteger $ diffTimeToPicoseconds $ utctDayTime time
201
- pure (day, dayTime)
200
+ Dir. getModificationTime f
202
201
#else
203
- withCString f $ \ f' ->
204
- alloca $ \ secPtr ->
205
- alloca $ \ nsecPtr -> do
206
- Posix. throwErrnoPathIfMinus1Retry_ " getmodtime" f $ c_getModTime f' secPtr nsecPtr
207
- CTime sec <- peek secPtr
208
- CLong nsec <- peek nsecPtr
209
- pure (sec, nsec)
210
-
211
- -- Sadly even unix’s getFileStatus + modificationTimeHiRes is still about twice as slow
212
- -- as doing the FFI call ourselves :(.
213
- foreign import ccall " getmodtime" c_getModTime :: CString -> Ptr CTime -> Ptr CLong -> IO Int
202
+ modificationTimeHiRes <$> getFileStatus f
214
203
#endif
215
204
216
205
modificationTime :: FileVersion -> Maybe UTCTime
217
- modificationTime VFSVersion {} = Nothing
218
- modificationTime (ModificationTime large small) = Just $ internalTimeToUTCTime large small
219
-
220
- internalTimeToUTCTime :: Int64 -> Int64 -> UTCTime
221
- internalTimeToUTCTime large small =
222
- #ifdef mingw32_HOST_OS
223
- UTCTime (ModifiedJulianDay $ fromIntegral large) (picosecondsToDiffTime $ fromIntegral small)
224
- #else
225
- systemToUTCTime $ MkSystemTime large (fromIntegral small)
226
- #endif
206
+ modificationTime VFSVersion {} = Nothing
207
+ modificationTime (ModificationTime posix) = Just $ posixSecondsToUTCTime posix
227
208
228
209
getFileContentsRule :: VFSHandle -> Rules ()
229
210
getFileContentsRule vfs = define $ \ GetFileContents file -> getFileContentsImpl vfs file
@@ -260,8 +241,8 @@ getFileContents f = do
260
241
liftIO $ case foi of
261
242
IsFOI Modified {} -> getCurrentTime
262
243
_ -> do
263
- (large,small) <- getModTime $ fromNormalizedFilePath f
264
- pure $ internalTimeToUTCTime large small
244
+ posix <- getModTime $ fromNormalizedFilePath f
245
+ pure $ posixSecondsToUTCTime posix
265
246
return (modTime, txt)
266
247
267
248
fileStoreRules :: VFSHandle -> (NormalizedFilePath -> Action Bool ) -> Rules ()
0 commit comments