2012-06-19 06:40:21 +00:00
|
|
|
{- git-annex assistant change tracking
|
|
|
|
-
|
2013-04-24 20:13:22 +00:00
|
|
|
- Copyright 2012-2013 Joey Hess <joey@kitenet.net>
|
2012-06-23 05:20:40 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
2012-06-19 06:40:21 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Changes where
|
|
|
|
|
2012-10-29 23:30:23 +00:00
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.Types.Changes
|
2013-04-24 20:13:22 +00:00
|
|
|
import Utility.TList
|
2012-06-19 06:40:21 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock
|
2013-03-11 01:36:13 +00:00
|
|
|
import Control.Concurrent.STM
|
2012-06-19 06:40:21 +00:00
|
|
|
|
|
|
|
{- Handlers call this when they made a change that needs to get committed. -}
|
2013-03-10 22:16:03 +00:00
|
|
|
madeChange :: FilePath -> ChangeInfo -> Assistant (Maybe Change)
|
2012-10-29 23:30:23 +00:00
|
|
|
madeChange f t = Just <$> (Change <$> liftIO getCurrentTime <*> pure f <*> pure t)
|
2012-06-19 06:40:21 +00:00
|
|
|
|
2012-10-29 23:30:23 +00:00
|
|
|
noChange :: Assistant (Maybe Change)
|
2012-06-19 06:40:21 +00:00
|
|
|
noChange = return Nothing
|
|
|
|
|
always check with ls-files before adding new files
Makes it safe to use git annex unlock with the watcher/assistant.
And also to mix use of the watcher/assistant with regular files stored in git.
Long ago, I had avoided doing this check, except during the startup scan,
because it would be slow to run ls-files repeatedly.
But then I added the lsof check, and to make that fast, got it to detect
batch file adds. So let's move the ls-files check to also occur when it'll
have a batch, and can check them all with one call.
This does slow down adding a single file by just a bit, but really only
a little bit. (The lsof check is probably more expensive.) It also
speeds up the startup scan, especially when there are lots of new files
found by the scan.
Also, fixed the sleep for annex.delayadd to not run while the threadstate
lock is held, so it doesn't unnecessarily freeze everything else.
Also, --force no longer makes it skip the lsof check, which was not
documented, and seems never a good idea.
2012-10-02 21:34:22 +00:00
|
|
|
{- Indicates an add needs to be done, but has not started yet. -}
|
2012-10-29 23:30:23 +00:00
|
|
|
pendingAddChange :: FilePath -> Assistant (Maybe Change)
|
|
|
|
pendingAddChange f = Just <$> (PendingAddChange <$> liftIO getCurrentTime <*> pure f)
|
2012-06-20 23:04:16 +00:00
|
|
|
|
2012-06-19 06:40:21 +00:00
|
|
|
{- Gets all unhandled changes.
|
|
|
|
- Blocks until at least one change is made. -}
|
2012-10-29 23:30:23 +00:00
|
|
|
getChanges :: Assistant [Change]
|
2013-04-24 20:13:22 +00:00
|
|
|
getChanges = (atomically . getTList) <<~ changePool
|
2013-03-11 01:36:13 +00:00
|
|
|
|
|
|
|
{- Gets all unhandled changes, without blocking. -}
|
|
|
|
getAnyChanges :: Assistant [Change]
|
2013-04-25 05:33:44 +00:00
|
|
|
getAnyChanges = (atomically . takeTList) <<~ changePool
|
2012-06-19 06:40:21 +00:00
|
|
|
|
2013-04-24 20:13:22 +00:00
|
|
|
{- Puts unhandled changes back into the pool.
|
2012-06-19 06:40:21 +00:00
|
|
|
- Note: Original order is not preserved. -}
|
2012-10-29 23:30:23 +00:00
|
|
|
refillChanges :: [Change] -> Assistant ()
|
2013-04-24 20:13:22 +00:00
|
|
|
refillChanges cs = (atomically . flip appendTList cs) <<~ changePool
|
2012-06-22 17:39:44 +00:00
|
|
|
|
2013-04-24 20:13:22 +00:00
|
|
|
{- Records a change to the pool. -}
|
2012-10-29 23:30:23 +00:00
|
|
|
recordChange :: Change -> Assistant ()
|
2013-04-24 20:13:22 +00:00
|
|
|
recordChange c = (atomically . flip snocTList c) <<~ changePool
|
2013-04-24 21:46:46 +00:00
|
|
|
|
|
|
|
recordChanges :: [Change] -> Assistant ()
|
|
|
|
recordChanges = refillChanges
|