Skip to content

Commit eb69b81

Browse files
Change the representation of filestamps (#415)
* Change the representation of filestamps This is needed to be able to compare them, which we want to use for loading .hie and .hi files * Update src/Development/IDE/Core/FileStore.hs Co-Authored-By: Neil Mitchell <[email protected]> Co-authored-by: Neil Mitchell <[email protected]>
1 parent 64f6c6a commit eb69b81

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/Development/IDE/Core/FileStore.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ getModificationTimeRule :: VFSHandle -> Rules ()
9595
getModificationTimeRule vfs =
9696
defineEarlyCutoff $ \GetModificationTime file -> do
9797
let file' = fromNormalizedFilePath file
98-
let wrap time = (Just time, ([], Just $ ModificationTime time))
98+
let wrap time@(l,s) = (Just $ BS.pack $ show time, ([], Just $ ModificationTime l s))
9999
alwaysRerun
100100
mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file
101101
case mbVirtual of
102-
Just (virtualFileVersion -> ver) -> pure (Just $ BS.pack $ show ver, ([], Just $ VFSVersion ver))
102+
Just (virtualFileVersion -> ver) ->
103+
pure (Just $ BS.pack $ show ver, ([], Just $ VFSVersion ver))
103104
Nothing -> liftIO $ fmap wrap (getModTime file')
104105
`catch` \(e :: IOException) -> do
105106
let err | isDoesNotExistError e = "File does not exist: " ++ file'
@@ -115,19 +116,21 @@ getModificationTimeRule vfs =
115116
-- We might also want to try speeding this up on Windows at some point.
116117
-- TODO leverage DidChangeWatchedFile lsp notifications on clients that
117118
-- support them, as done for GetFileExists
118-
getModTime :: FilePath -> IO BS.ByteString
119+
getModTime :: FilePath -> IO (Int,Int)
119120
getModTime f =
120121
#ifdef mingw32_HOST_OS
121122
do time <- Dir.getModificationTime f
122-
pure $! BS.pack $ show (toModifiedJulianDay $ utctDay time, diffTimeToPicoseconds $ utctDayTime time)
123+
let !day = toModifiedJulianDay $ utctDay time
124+
!dayTime = diffTimeToPicoseconds $ utctDayTime time
125+
pure (day, dayTime)
123126
#else
124127
withCString f $ \f' ->
125128
alloca $ \secPtr ->
126129
alloca $ \nsecPtr -> do
127130
Posix.throwErrnoPathIfMinus1Retry_ "getmodtime" f $ c_getModTime f' secPtr nsecPtr
128131
sec <- peek secPtr
129132
nsec <- peek nsecPtr
130-
pure $! BS.pack $ show sec <> "." <> show nsec
133+
pure (fromEnum sec, fromIntegral nsec)
131134

132135
-- Sadly even unix’s getFileStatus + modificationTimeHiRes is still about twice as slow
133136
-- as doing the FFI call ourselves :(.

src/Development/IDE/Core/Shake.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module Development.IDE.Core.Shake(
3636
sendEvent,
3737
ideLogger,
3838
actionLogger,
39-
FileVersion(..),
39+
FileVersion(..), modificationTime,
4040
Priority(..),
4141
updatePositionMapping,
4242
deleteValue,
@@ -762,19 +762,22 @@ instance Binary GetModificationTime
762762
-- | Get the modification time of a file.
763763
type instance RuleResult GetModificationTime = FileVersion
764764

765-
-- | We store the modification time as a ByteString since we need
766-
-- a ByteString anyway for Shake and we do not care about how times
767-
-- are represented.
768-
data FileVersion = VFSVersion Int | ModificationTime BS.ByteString
765+
data FileVersion
766+
= VFSVersion Int
767+
| ModificationTime
768+
!Int -- ^ Large unit (platform dependent, do not make assumptions)
769+
!Int -- ^ Small unit (platform dependent, do not make assumptions)
769770
deriving (Show, Generic)
770771

771772
instance NFData FileVersion
772773

773774
vfsVersion :: FileVersion -> Maybe Int
774775
vfsVersion (VFSVersion i) = Just i
775-
vfsVersion (ModificationTime _) = Nothing
776-
776+
vfsVersion ModificationTime{} = Nothing
777777

778+
modificationTime :: FileVersion -> Maybe (Int, Int)
779+
modificationTime VFSVersion{} = Nothing
780+
modificationTime (ModificationTime large small) = Just (large, small)
778781

779782
getDiagnosticsFromStore :: StoreItem -> [Diagnostic]
780783
getDiagnosticsFromStore (StoreItem _ diags) = concatMap SL.fromSortedList $ Map.elems diags

0 commit comments

Comments
 (0)