fix hang when built with unix-2.8
authorJoey Hess <joeyh@joeyh.name>
Wed, 2 Aug 2023 00:17:29 +0000 (20:17 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 2 Aug 2023 00:22:28 +0000 (20:22 -0400)
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

index ec4eab2baa9884953c6a104ba3479c7f5ba4ee03..4961499f62963b2e5f985263439ca4a3577f7e1e 100644 (file)
@@ -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