Files
ports/devel/git-annex/patches/patch-Utility_DirWatcher_Kqueue_hs
gnezdo 4ebe3d9bb8 Upgrade git-annex to 10.20260115 supporting ghc 9.10.3
Remove the docs from git-annex as new hackage versions miss them

There's no obvious place outside main git repository to get the docs.

OK kili@
2026-02-15 23:35:44 +00:00

159 lines
5.4 KiB
Plaintext

From d056b885ac42c0c8c11499b91718525e589e6707 Mon Sep 17 00:00:00 2001
From: Greg Steuck <greg@nest.cx>
Date: Sun, 8 Feb 2026 10:58:27 -0800
Subject: [PATCH] Kqueue: update to OsPath
Finish the OsPath migration for Utility/DirWatcher/Kqueue.hs that was
incomplete in 033e4b086ffdac81072dd7d2cb0d2cc2c13e81a8.
---
Utility/DirWatcher/Kqueue.hs | 45 ++++++++++++++++++------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/Utility/DirWatcher/Kqueue.hs b/Utility/DirWatcher/Kqueue.hs
index eb57b09334..61be3fffd8 100644
--- Utility/DirWatcher/Kqueue.hs
+++ Utility/DirWatcher/Kqueue.hs
@@ -20,6 +20,7 @@ module Utility.DirWatcher.Kqueue (
import Common
import Utility.DirWatcher.Types
import Utility.OpenFd
+import qualified Utility.RawFilePath as R
import System.Posix.Types
import Foreign.C.Types
@@ -33,9 +34,9 @@ import qualified System.Posix.IO as Posix
import Control.Concurrent
data Change
- = Deleted FilePath
- | DeletedDir FilePath
- | Added FilePath
+ = Deleted OsPath
+ | DeletedDir OsPath
+ | Added OsPath
deriving (Show)
isAdd :: Change -> Bool
@@ -43,26 +44,26 @@ isAdd (Added _) = True
isAdd (Deleted _) = False
isAdd (DeletedDir _) = False
-changedFile :: Change -> FilePath
+changedFile :: Change -> OsPath
changedFile (Added f) = f
changedFile (Deleted f) = f
changedFile (DeletedDir f) = f
-data Kqueue = Kqueue
+data Kqueue = Kqueue
{ kqueueFd :: Fd
- , kqueueTop :: FilePath
+ , kqueueTop :: OsPath
, kqueueMap :: DirMap
, _kqueuePruner :: Pruner
}
-type Pruner = FilePath -> Bool
+type Pruner = OsPath -> Bool
type DirMap = M.Map Fd DirInfo
{- Enough information to uniquely identify a file in a directory,
- but not too much. -}
data DirEnt = DirEnt
- { dirEnt :: FilePath -- relative to the parent directory
+ { dirEnt :: OsPath -- relative to the parent directory
, _dirInode :: FileID -- included to notice file replacements
, isSubDir :: Bool
}
@@ -70,20 +71,20 @@ data DirEnt = DirEnt
{- A directory, and its last known contents. -}
data DirInfo = DirInfo
- { dirName :: FilePath
+ { dirName :: OsPath
, dirCache :: S.Set DirEnt
}
deriving (Show)
-getDirInfo :: FilePath -> IO DirInfo
+getDirInfo :: OsPath -> IO DirInfo
getDirInfo dir = do
- l <- filter (not . dirCruft . toRawFilePath) <$> getDirectoryContents dir
+ l <- filter (`notElem` dirCruft) <$> getDirectoryContents dir
contents <- S.fromList . catMaybes <$> mapM getDirEnt l
return $ DirInfo dir contents
where
getDirEnt f = catchMaybeIO $ do
- s <- getSymbolicLinkStatus (dir </> f)
- return $ DirEnt f (fileID s) (isDirectory s)
+ s <- R.getSymbolicLinkStatus $ fromOsPath $ dir </> f
+ return $ DirEnt f (Posix.fileID s) (Posix.isDirectory s)
{- Difference between the dirCaches of two DirInfos. -}
(//) :: DirInfo -> DirInfo -> [Change]
@@ -99,7 +100,7 @@ oldc // newc = deleted ++ added
{- Builds a map of directories in a tree, possibly pruning some.
- Opens each directory in the tree, and records its current contents. -}
-scanRecursive :: FilePath -> Pruner -> IO DirMap
+scanRecursive :: OsPath -> Pruner -> IO DirMap
scanRecursive topdir prune = M.fromList <$> walk [] [topdir]
where
walk c [] = return c
@@ -111,7 +112,7 @@ scanRecursive topdir prune = M.fromList <$> walk [] [topdir]
Nothing -> walk c rest
Just info -> do
mfd <- catchMaybeIO $
- openFdWithMode (toRawFilePath dir) Posix.ReadOnly Nothing
+ openFdWithMode (fromOsPath dir) Posix.ReadOnly Nothing
Posix.defaultFileFlags
(CloseOnExecFlag True)
case mfd of
@@ -124,22 +125,22 @@ scanRecursive topdir prune = M.fromList <$> walk [] [topdir]
{- Adds a list of subdirectories (and all their children), unless pruned to a
- directory map. Adding a subdirectory that's already in the map will
- cause its contents to be refreshed. -}
-addSubDirs :: DirMap -> Pruner -> [FilePath] -> IO DirMap
+addSubDirs :: DirMap -> Pruner -> [OsPath] -> IO DirMap
addSubDirs dirmap prune dirs = do
newmap <- foldr M.union M.empty <$>
mapM (\d -> scanRecursive d prune) dirs
return $ M.union newmap dirmap -- prefer newmap
{- Removes a subdirectory (and all its children) from a directory map. -}
-removeSubDir :: DirMap -> FilePath -> IO DirMap
+removeSubDir :: DirMap -> OsPath -> IO DirMap
removeSubDir dirmap dir = do
mapM_ Posix.closeFd $ M.keys toremove
return rest
where
- (toremove, rest) = M.partition (dirContains (toRawFilePath dir) . toRawFilePath . dirName) dirmap
+ (toremove, rest) = M.partition (dirContains dir . dirName) dirmap
-findDirContents :: DirMap -> FilePath -> [FilePath]
-findDirContents dirmap dir = concatMap absolutecontents $ search
+findDirContents :: DirMap -> OsPath -> [OsPath]
+findDirContents dirmap dir = concatMap absolutecontents search
where
absolutecontents i = map (dirName i </>)
(map dirEnt $ S.toList $ dirCache i)
@@ -154,7 +155,7 @@ foreign import ccall safe "libkqueue.h waitchange_kqueue" c_waitchange_kqueue
:: Fd -> IO Fd
{- Initializes a Kqueue to watch a directory, and all its subdirectories. -}
-initKqueue :: FilePath -> Pruner -> IO Kqueue
+initKqueue :: OsPath -> Pruner -> IO Kqueue
initKqueue dir pruned = do
dirmap <- scanRecursive dir pruned
h <- c_init_kqueue
@@ -268,4 +269,4 @@ runHooks kq hooks = do
Just a -> a (changedFile change) s
withstatus change a = maybe noop (a change) =<<
- (catchMaybeIO (getSymbolicLinkStatus (changedFile change)))
+ catchMaybeIO (R.getSymbolicLinkStatus (fromOsPath (changedFile change)))
--
2.52.0