avoid trying to use lsof when it's not in path and --forced

This commit is contained in:
Joey Hess 2013-12-04 17:39:44 -04:00
parent abb0b3103f
commit 9d323a98e2

View file

@ -46,11 +46,12 @@ import Control.Concurrent
{- This thread makes git commits at appropriate times. -} {- This thread makes git commits at appropriate times. -}
commitThread :: NamedThread commitThread :: NamedThread
commitThread = namedThread "Committer" $ do commitThread = namedThread "Committer" $ do
havelsof <- liftIO $ inPath "lsof"
delayadd <- liftAnnex $ delayadd <- liftAnnex $
maybe delayaddDefault (return . Just . Seconds) maybe delayaddDefault (return . Just . Seconds)
=<< annexDelayAdd <$> Annex.getGitConfig =<< annexDelayAdd <$> Annex.getGitConfig
waitChangeTime $ \(changes, time) -> do waitChangeTime $ \(changes, time) -> do
readychanges <- handleAdds delayadd changes readychanges <- handleAdds havelsof delayadd changes
if shouldCommit time (length readychanges) readychanges if shouldCommit time (length readychanges) readychanges
then do then do
debug debug
@ -252,14 +253,14 @@ delayaddDefault = return Nothing
- Any pending adds that are not ready yet are put back into the ChangeChan, - Any pending adds that are not ready yet are put back into the ChangeChan,
- where they will be retried later. - where they will be retried later.
-} -}
handleAdds :: Maybe Seconds -> [Change] -> Assistant [Change] handleAdds :: Bool -> Maybe Seconds -> [Change] -> Assistant [Change]
handleAdds delayadd cs = returnWhen (null incomplete) $ do handleAdds havelsof delayadd cs = returnWhen (null incomplete) $ do
let (pending, inprocess) = partition isPendingAddChange incomplete let (pending, inprocess) = partition isPendingAddChange incomplete
direct <- liftAnnex isDirect direct <- liftAnnex isDirect
(pending', cleanup) <- if direct (pending', cleanup) <- if direct
then return (pending, noop) then return (pending, noop)
else findnew pending else findnew pending
(postponed, toadd) <- partitionEithers <$> safeToAdd delayadd pending' inprocess (postponed, toadd) <- partitionEithers <$> safeToAdd havelsof delayadd pending' inprocess
cleanup cleanup
unless (null postponed) $ unless (null postponed) $
@ -273,7 +274,7 @@ handleAdds delayadd cs = returnWhen (null incomplete) $ do
if DirWatcher.eventsCoalesce || null added || direct if DirWatcher.eventsCoalesce || null added || direct
then return $ added ++ otherchanges then return $ added ++ otherchanges
else do else do
r <- handleAdds delayadd =<< getChanges r <- handleAdds havelsof delayadd =<< getChanges
return $ r ++ added ++ otherchanges return $ r ++ added ++ otherchanges
where where
(incomplete, otherchanges) = partition (\c -> isPendingAddChange c || isInProcessAddChange c) cs (incomplete, otherchanges) = partition (\c -> isPendingAddChange c || isInProcessAddChange c) cs
@ -386,15 +387,17 @@ handleAdds delayadd cs = returnWhen (null incomplete) $ do
- -
- Check by running lsof on the repository. - Check by running lsof on the repository.
-} -}
safeToAdd :: Maybe Seconds -> [Change] -> [Change] -> Assistant [Either Change Change] safeToAdd :: Bool -> Maybe Seconds -> [Change] -> [Change] -> Assistant [Either Change Change]
safeToAdd _ [] [] = return [] safeToAdd _ _ [] [] = return []
safeToAdd delayadd pending inprocess = do safeToAdd havelsof delayadd pending inprocess = do
maybe noop (liftIO . threadDelaySeconds) delayadd maybe noop (liftIO . threadDelaySeconds) delayadd
liftAnnex $ do liftAnnex $ do
keysources <- forM pending $ Command.Add.lockDown . changeFile keysources <- forM pending $ Command.Add.lockDown . changeFile
let inprocess' = inprocess ++ mapMaybe mkinprocess (zip pending keysources) let inprocess' = inprocess ++ mapMaybe mkinprocess (zip pending keysources)
openfiles <- S.fromList . map fst3 . filter openwrite <$> openfiles <- if havelsof
findopenfiles (map keySource inprocess') then S.fromList . map fst3 . filter openwrite <$>
findopenfiles (map keySource inprocess')
else pure S.empty
let checked = map (check openfiles) inprocess' let checked = map (check openfiles) inprocess'
{- If new events are received when files are closed, {- If new events are received when files are closed,