@@ -19,7 +19,8 @@ module Development.IDE.Core.FileStore(
19
19
resetInterfaceStore ,
20
20
getModificationTimeImpl ,
21
21
addIdeGlobal ,
22
- getFileContentsImpl
22
+ getFileContentsImpl ,
23
+ getModTime
23
24
) where
24
25
25
26
import Control.Concurrent.STM (atomically )
@@ -31,37 +32,30 @@ import Control.Monad.IO.Class
31
32
import qualified Data.ByteString as BS
32
33
import Data.Either.Extra
33
34
import qualified Data.HashMap.Strict as HM
34
- import Data.Int (Int64 )
35
35
import qualified Data.Map.Strict as Map
36
36
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
53
54
54
55
#ifdef mingw32_HOST_OS
55
56
import qualified System.Directory as Dir
56
57
#else
57
- import Data.Time.Clock.System (SystemTime (MkSystemTime ),
58
- systemToUTCTime )
59
- import Foreign.C.String
60
- import Foreign.C.Types
61
- import Foreign.Marshal (alloca )
62
- import Foreign.Ptr
63
- import Foreign.Storable
64
- import qualified System.Posix.Error as Posix
58
+ import System.Posix.Files ( getFileStatus , modificationTimeHiRes )
65
59
#endif
66
60
67
61
import qualified Development.IDE.Types.Logger as L
@@ -126,7 +120,7 @@ getModificationTimeImpl :: VFSHandle
126
120
(Maybe BS. ByteString , ([FileDiagnostic ], Maybe FileVersion ))
127
121
getModificationTimeImpl vfs isWatched missingFileDiags file = do
128
122
let file' = fromNormalizedFilePath file
129
- let wrap time@ (l,s) = (Just $ LBS. toStrict $ B. encode time, ([] , Just $ ModificationTime l s ))
123
+ let wrap time = (Just $ LBS. toStrict $ B. encode $ toRational time, ([] , Just $ ModificationTime time ))
130
124
mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file
131
125
case mbVirtual of
132
126
Just (virtualFileVersion -> ver) -> do
@@ -192,38 +186,17 @@ resetFileStore ideState changes = mask $ \_ ->
192
186
-- We might also want to try speeding this up on Windows at some point.
193
187
-- TODO leverage DidChangeWatchedFile lsp notifications on clients that
194
188
-- support them, as done for GetFileExists
195
- getModTime :: FilePath -> IO ( Int64 , Int64 )
189
+ getModTime :: FilePath -> IO POSIXTime
196
190
getModTime f =
197
191
#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)
192
+ utcTimeToPOSIXSeconds <$> Dir. getModificationTime f
202
193
#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
194
+ modificationTimeHiRes <$> getFileStatus f
214
195
#endif
215
196
216
197
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
198
+ modificationTime VFSVersion {} = Nothing
199
+ modificationTime (ModificationTime posix) = Just $ posixSecondsToUTCTime posix
227
200
228
201
getFileContentsRule :: VFSHandle -> Rules ()
229
202
getFileContentsRule vfs = define $ \ GetFileContents file -> getFileContentsImpl vfs file
@@ -260,8 +233,8 @@ getFileContents f = do
260
233
liftIO $ case foi of
261
234
IsFOI Modified {} -> getCurrentTime
262
235
_ -> do
263
- (large,small) <- getModTime $ fromNormalizedFilePath f
264
- pure $ internalTimeToUTCTime large small
236
+ posix <- getModTime $ fromNormalizedFilePath f
237
+ pure $ posixSecondsToUTCTime posix
265
238
return (modTime, txt)
266
239
267
240
fileStoreRules :: VFSHandle -> (NormalizedFilePath -> Action Bool ) -> Rules ()
0 commit comments