1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 04:41:47 +03:00

Ensure we treat /dev/null as empty.

This commit is contained in:
Rob Rix 2017-08-11 09:57:03 -04:00
parent 1f26be577a
commit 0e2c418038

View File

@ -29,6 +29,7 @@ import Text.Read
-- | Read a utf8-encoded file to a 'Blob'.
readFile :: forall m. MonadIO m => FilePath -> Maybe Language -> m Blob.Blob
readFile path@"/dev/null" _ = pure (Blob.emptyBlob path)
readFile path language = do
raw <- liftIO $ (Just <$> B.readFile path) `catch` (const (pure Nothing) :: IOException -> IO (Maybe B.ByteString))
pure $ fromMaybe (Blob.emptyBlob path) (Blob.sourceBlob path language . fromBytes <$> raw)