check symlink before reading file

This is faster because when multiple files are in a directory, it gets
cached.
This commit is contained in:
Joey Hess 2021-06-14 11:53:51 -04:00
parent 4163344ed6
commit c4f1465a81
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 13 additions and 8 deletions

View file

@ -301,7 +301,7 @@ unpaddedMaxPointerSz = 8192
- symlink does. Avoids a false positive in those cases. - symlink does. Avoids a false positive in those cases.
- -} - -}
isPointerFile :: RawFilePath -> IO (Maybe Key) isPointerFile :: RawFilePath -> IO (Maybe Key)
isPointerFile f = catchDefaultIO Nothing $ do isPointerFile f = catchDefaultIO Nothing $
#if defined(mingw32_HOST_OS) #if defined(mingw32_HOST_OS)
checkcontentfollowssymlinks -- no symlinks supported on windows checkcontentfollowssymlinks -- no symlinks supported on windows
#else #else
@ -311,13 +311,10 @@ isPointerFile f = catchDefaultIO Nothing $ do
closeFd closeFd
(\fd -> readhandle =<< fdToHandle fd) (\fd -> readhandle =<< fdToHandle fd)
#else #else
pointercontent <- checkcontentfollowssymlinks ifM (isSymbolicLink <$> R.getSymbolicLinkStatus f)
if isJust pointercontent
then ifM (isSymbolicLink <$> R.getSymbolicLinkStatus f)
( return Nothing ( return Nothing
, return pointercontent , checkcontentfollowssymlinks
) )
else return Nothing
#endif #endif
#endif #endif
where where

View file

@ -0,0 +1,8 @@
[[!comment format=mdwn
username="joey"
subject="""comment 25"""
date="2021-06-14T15:52:37Z"
content="""
Found an optimisation that sped it up 50%, but this edge case is still
`O(N^2)`, so *shrug*.
"""]]