From 3a52b4c4c35baa85b7d55a73df3e48b19b1a8ddf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 1 Aug 2023 20:17:29 -0400 Subject: [PATCH] fix hang when built with unix-2.8 git-annex test hang when running git-annex add in an adjusted unlocked branch. I couldn't seem to reproduce the hang outside the test suite. Seems that the code added in 26a9ea12d11f85b43987d863449c790f7320d9d1 was buggy, and as that commit was made without testing it, building with unix-2.8 exposed the bug. I don't fully understand the bug, which involves fdToHandle and then closing the fd, vs closing the handle. May somehow involve laziness or forcing around the S.hGet? Using hClose solved it in any case. (Also eliminated checkcontentfollowssymlinks to fix a build warning when it's not used.) --- Annex/Link.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Annex/Link.hs b/Annex/Link.hs index ec4eab2baa..4961499f62 100644 --- a/Annex/Link.hs +++ b/Annex/Link.hs @@ -434,23 +434,22 @@ maxSymlinkSz = 8192 isPointerFile :: RawFilePath -> IO (Maybe Key) isPointerFile f = catchDefaultIO Nothing $ #if defined(mingw32_HOST_OS) - checkcontentfollowssymlinks -- no symlinks supported on windows + withFile (fromRawFilePath f) ReadMode readhandle #else #if MIN_VERSION_unix(2,8,0) - bracket - (openFd (fromRawFilePath f) ReadOnly (defaultFileFlags { nofollow = True })) - closeFd - (\fd -> readhandle =<< fdToHandle fd) + let open = do + fd <- openFd (fromRawFilePath f) ReadOnly + (defaultFileFlags { nofollow = True }) + fdToHandle fd + in bracket open hClose readhandle #else ifM (isSymbolicLink <$> R.getSymbolicLinkStatus f) ( return Nothing - , checkcontentfollowssymlinks + , withFile (fromRawFilePath f) ReadMode readhandle ) #endif #endif where - checkcontentfollowssymlinks = - withFile (fromRawFilePath f) ReadMode readhandle readhandle h = parseLinkTargetOrPointer <$> S.hGet h maxPointerSz {- Checks a symlink target or pointer file first line to see if it -- 2.30.2