fix build with unix-2.8.0
authorJoey Hess <joeyh@joeyh.name>
Tue, 1 Aug 2023 22:41:27 +0000 (18:41 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 1 Aug 2023 22:41:27 +0000 (18:41 -0400)
Changed the parameters to openFd. So needed to add a small wrapper
library to keep supporting older versions as well.

12 files changed:
Assistant/Sync.hs
CHANGELOG
Command/RemoteDaemon.hs
Git/LockFile.hs
Remote/Directory.hs
Utility/Daemon.hs
Utility/DirWatcher/Kqueue.hs
Utility/LockFile/PidLock.hs
Utility/LockFile/Posix.hs
Utility/OpenFd.hs [new file with mode: 0644]
Utility/Url.hs
git-annex.cabal

index c7907d777c11187cc790bb0e728a98fef7fca0cf..9ec60c25e467ef3e5e69e9c7391548e3f02dc252 100644 (file)
@@ -75,15 +75,15 @@ reconnectRemotes rs = void $ do
                | Git.repoIsLocal r = True
                | Git.repoIsLocalUnknown r = True
                | otherwise = False
-       sync currentbranch@(Just _, _) = do
+       syncbranch currentbranch@(Just _, _) = do
                (failedpull, diverged) <- manualPull currentbranch =<< gitremotes
                now <- liftIO getCurrentTime
                failedpush <- pushToRemotes' now =<< gitremotes
                return (nub $ failedpull ++ failedpush, diverged)
        {- No local branch exists yet, but we can try pulling. -}
-       sync (Nothing, _) = manualPull (Nothing, Nothing) =<< gitremotes
+       syncbranch (Nothing, _) = manualPull (Nothing, Nothing) =<< gitremotes
        go = do
-               (failed, diverged) <- sync =<< liftAnnex getCurrentBranch
+               (failed, diverged) <- syncbranch =<< liftAnnex getCurrentBranch
                addScanRemotes diverged =<<
                        filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) rs
                return failed
index 4c37c3715de9b86b043f75a5dce130a8e6fa8232..dba3259b0002d5444b845a42c63306976a594cc9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -35,6 +35,7 @@ git-annex (10.20230627) UNRELEASED; urgency=medium
     Anything still relying on that, eg via cabal v1-install will need to
     change to using make install-home.a
   * git-annex.cabal: Support building with unix-compat 0.7
+  * Support building with unix-2.8.0.
 
  -- Joey Hess <id@joeyh.name>  Mon, 26 Jun 2023 13:10:40 -0400
 
index 114c0afcee2dcea1f8ac83d88191669a14494e88..03f5eaaf3db3d064dfb7d896d05d0bad9b313e6a 100644 (file)
@@ -14,6 +14,7 @@ import RemoteDaemon.Core
 import Utility.Daemon
 #ifndef mingw32_HOST_OS
 import Annex.Path
+import Utility.OpenFd
 #endif
 
 cmd :: Command
@@ -30,7 +31,7 @@ run o
 #ifndef mingw32_HOST_OS
                git_annex <- liftIO programPath
                ps <- gitAnnexDaemonizeParams
-               let logfd = openFd "/dev/null" ReadOnly Nothing defaultFileFlags
+               let logfd = openFdWithMode (toRawFilePath "/dev/null") ReadOnly Nothing defaultFileFlags
                liftIO $ daemonize git_annex ps logfd Nothing False runNonInteractive
 #else
                liftIO $ foreground Nothing runNonInteractive   
index 218a9588cdbadcc149710122eecdbd7efafb805b..fa92df046e8470a7b702f360808e94271f71ac09 100644 (file)
@@ -12,6 +12,7 @@ module Git.LockFile where
 import Common
 
 #ifndef mingw32_HOST_OS
+import Utility.OpenFd
 import System.Posix.Types
 import System.Posix.IO
 #else
@@ -51,7 +52,7 @@ openLock' :: FilePath -> IO LockHandle
 openLock' lck = do
 #ifndef mingw32_HOST_OS
        -- On unix, git simply uses O_EXCL
-       h <- openFd lck ReadWrite (Just 0O666)
+       h <- openFdWithMode (toRawFilePath lck) ReadWrite (Just 0O666)
                (defaultFileFlags { exclusive = True })
        setFdOption h CloseOnExec True
 #else
index b5f756716c7e1dadf4bdf6b263b81c5ab8cc8283..d234ff59cbac119f1133d3292ebecec3f0888877 100644 (file)
@@ -50,6 +50,9 @@ import Utility.InodeCache
 import Utility.FileMode
 import Utility.Directory.Create
 import qualified Utility.RawFilePath as R
+#ifndef mingw32_HOST_OS
+import Utility.OpenFd
+#endif
 
 remote :: RemoteType
 remote = specialRemoteType $ RemoteType
@@ -469,7 +472,7 @@ retrieveExportWithContentIdentifierM ii dir cow loc cids dest gk p =
 #ifndef mingw32_HOST_OS
                let open = do
                        -- Need a duplicate fd for the post check.
-                       fd <- openFd f' ReadOnly Nothing defaultFileFlags
+                       fd <- openFdWithMode f ReadOnly Nothing defaultFileFlags
                        dupfd <- dup fd
                        h <- fdToHandle fd
                        return (h, dupfd)
index 6676ed4e3d639e51ae223fcc9a73ad90eaabe3e1..c2a3d1bde7da831e6f1e283aa166f3abe8f890e0 100644 (file)
@@ -21,6 +21,7 @@ import Utility.PID
 #ifndef mingw32_HOST_OS
 import Utility.LogFile
 import Utility.Env
+import Utility.OpenFd
 #else
 import System.Win32.Process (terminateProcessById)
 import Utility.LockFile
@@ -49,7 +50,7 @@ daemonize cmd params openlogfd pidfile changedirectory a = do
                        maybe noop lockPidFile pidfile 
                        a
                _ -> do
-                       nullfd <- openFd "/dev/null" ReadOnly Nothing defaultFileFlags
+                       nullfd <- openFdWithMode (toRawFilePath "/dev/null") ReadOnly Nothing defaultFileFlags
                        redir nullfd stdInput
                        redirLog =<< openlogfd
                        environ <- getEnvironment
@@ -95,9 +96,9 @@ foreground pidfile a = do
 lockPidFile :: FilePath -> IO ()
 lockPidFile pidfile = do
 #ifndef mingw32_HOST_OS
-       fd <- openFd pidfile ReadWrite (Just stdFileMode) defaultFileFlags
+       fd <- openFdWithMode (toRawFilePath pidfile) ReadWrite (Just stdFileMode) defaultFileFlags
        locked <- catchMaybeIO $ setLock fd (WriteLock, AbsoluteSeek, 0, 0)
-       fd' <- openFd newfile ReadWrite (Just stdFileMode) defaultFileFlags
+       fd' <- openFdWithMode (toRawFilePath newfile) ReadWrite (Just stdFileMode) defaultFileFlags
                { trunc = True }
        locked' <- catchMaybeIO $ setLock fd' (WriteLock, AbsoluteSeek, 0, 0)
        case (locked, locked') of
@@ -132,7 +133,7 @@ checkDaemon :: FilePath -> IO (Maybe PID)
 checkDaemon pidfile = bracket setup cleanup go
   where
        setup = catchMaybeIO $
-               openFd pidfile ReadOnly (Just stdFileMode) defaultFileFlags
+               openFdWithMode (toRawFilePath pidfile) ReadOnly (Just stdFileMode) defaultFileFlags
        cleanup (Just fd) = closeFd fd
        cleanup Nothing = return ()
        go (Just fd) = catchDefaultIO Nothing $ do
index 0c84f67c198a94a25a2a856da487c93a1fd2e6f1..dc9fed31c202f403b60b3b35767b2a3f598bcaed 100644 (file)
@@ -19,6 +19,7 @@ module Utility.DirWatcher.Kqueue (
 
 import Common
 import Utility.DirWatcher.Types
+import Utility.OpenFd
 
 import System.Posix.Types
 import Foreign.C.Types
@@ -110,7 +111,7 @@ scanRecursive topdir prune = M.fromList <$> walk [] [topdir]
                                Nothing -> walk c rest
                                Just info -> do
                                        mfd <- catchMaybeIO $
-                                               Posix.openFd dir Posix.ReadOnly Nothing Posix.defaultFileFlags
+                                               openFdWithMode (toRawFilePath dir) Posix.ReadOnly Nothing Posix.defaultFileFlags
                                        case mfd of
                                                Nothing -> walk c rest
                                                Just fd -> do
index c66048018708c534f19b3bd6bc985c99554f93a7..be4548b0b6ee5da98dd89b5cf362c7bf1479f3d9 100644 (file)
@@ -30,6 +30,7 @@ import Utility.Directory
 import Utility.Monad
 import Utility.Path.AbsRel
 import Utility.FileMode
+import Utility.OpenFd
 import Utility.LockFile.LockStatus
 import Utility.ThreadScheduler
 import Utility.Hash
@@ -204,7 +205,7 @@ linkToLock (Just _) src dest = do
                                )
                Left _ -> catchMaybeIO $ do
                        let setup = do
-                               fd <- openFd dest WriteOnly
+                               fd <- openFdWithMode dest WriteOnly
                                        (Just $ combineModes readModes)
                                        (defaultFileFlags {exclusive = True})
                                fdToHandle fd
index aaec35e98ef68b1337340aa48eb5f63bd2e06018..e7d49b81e30a19d5711a731327e075951f717e11 100644 (file)
@@ -24,6 +24,7 @@ import Utility.Exception
 import Utility.Applicative
 import Utility.FileMode
 import Utility.LockFile.LockStatus
+import Utility.OpenFd
 
 import System.IO
 import System.Posix.Types
@@ -75,7 +76,7 @@ tryLock lockreq mode lockfile = uninterruptibleMask_ $ do
 openLockFile :: LockRequest -> Maybe ModeSetter -> LockFile -> IO Fd
 openLockFile lockreq filemode lockfile = do
        l <- applyModeSetter filemode lockfile $ \filemode' ->
-               openFd lockfile openfor filemode' defaultFileFlags
+               openFdWithMode lockfile openfor filemode' defaultFileFlags
        setFdOption l CloseOnExec True
        return l
   where
diff --git a/Utility/OpenFd.hs b/Utility/OpenFd.hs
new file mode 100644 (file)
index 0000000..c46e36f
--- /dev/null
@@ -0,0 +1,25 @@
+{- openFd wrapper to support old versions of unix package.
+ -
+ - Copyright 2023 Joey Hess <id@joeyh.name>
+ -
+ - License: BSD-2-clause
+ -}
+
+{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -fno-warn-tabs #-}
+
+module Utility.OpenFd (
+       openFdWithMode,
+) where
+
+import System.Posix.IO.ByteString
+import System.Posix.Types
+import System.FilePath.ByteString (RawFilePath)
+
+openFdWithMode :: RawFilePath -> OpenMode -> Maybe FileMode -> OpenFileFlags -> IO Fd
+#if MIN_VERSION_unix(2,8,0)
+openFdWithMode f openmode filemode flags = 
+       openFd f openmode (flags { creat = filemode })
+#else
+openFdWithMode = openFd
+#endif
index 1f237dc0c1e270d9ce9482b3a48f767605b3d27d..e74ee0a26c6cd05e65131bd6920804c3e80fb7a7 100644 (file)
@@ -55,7 +55,6 @@ import Utility.Hash (IncrementalVerifier(..))
 
 import Network.URI
 import Network.HTTP.Types
-import qualified Network.Connection as NC
 import qualified Data.CaseInsensitive as CI
 import qualified Data.ByteString as B
 import qualified Data.ByteString.UTF8 as B8
@@ -745,8 +744,8 @@ curlRestrictedParams r u defport ps = case uriAuthority u of
                case partitionEithers (map checkrestriction addrs) of
                        ((e:_es), []) -> throwIO e
                        (_, as)
-                               | null as -> throwIO $ 
-                                       NC.HostNotResolved hostname
+                               | null as -> giveup $ 
+                                       "cannot resolve host " ++ hostname
                                | otherwise -> return $
                                        (limitresolve p) as ++ ps
        checkrestriction addr = maybe (Right addr) Left $
index 24b32e414720d219657850e59d84d45af13dd04b..5495a06c11a989dac6bd4e604a3b87c9df9492c5 100644 (file)
@@ -1132,6 +1132,7 @@ Executable git-annex
     Utility.MoveFile
     Utility.Network
     Utility.NotificationBroadcaster
+    Utility.OpenFd
     Utility.OptParse
     Utility.OSX
     Utility.PID