2012-06-19 06:40:21 +00:00
|
|
|
{- git-annex assistant change tracking
|
|
|
|
-
|
|
|
|
- Copyright 2012 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
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import qualified Annex.Queue
|
2012-06-20 23:04:16 +00:00
|
|
|
import Types.KeySource
|
2012-06-22 17:39:44 +00:00
|
|
|
import Utility.TSet
|
2012-06-19 06:40:21 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock
|
|
|
|
|
2012-06-20 23:04:16 +00:00
|
|
|
data ChangeType = AddChange | LinkChange | RmChange | RmDirChange
|
2012-06-19 06:40:21 +00:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2012-06-22 17:39:44 +00:00
|
|
|
type ChangeChan = TSet Change
|
2012-06-19 06:40:21 +00:00
|
|
|
|
2012-06-20 23:04:16 +00:00
|
|
|
data Change
|
|
|
|
= Change
|
|
|
|
{ changeTime :: UTCTime
|
|
|
|
, changeFile :: FilePath
|
|
|
|
, changeType :: ChangeType
|
|
|
|
}
|
|
|
|
| PendingAddChange
|
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
|
|
|
{ changeTime ::UTCTime
|
|
|
|
, changeFile :: FilePath
|
|
|
|
}
|
|
|
|
| InProcessAddChange
|
2012-06-20 23:04:16 +00:00
|
|
|
{ changeTime ::UTCTime
|
|
|
|
, keySource :: KeySource
|
|
|
|
}
|
2012-06-19 06:40:21 +00:00
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
newChangeChan :: IO ChangeChan
|
2012-06-22 17:39:44 +00:00
|
|
|
newChangeChan = newTSet
|
2012-06-19 06:40:21 +00:00
|
|
|
|
|
|
|
{- Handlers call this when they made a change that needs to get committed. -}
|
|
|
|
madeChange :: FilePath -> ChangeType -> Annex (Maybe Change)
|
|
|
|
madeChange f t = do
|
|
|
|
-- Just in case the commit thread is not flushing the queue fast enough.
|
2012-06-20 23:04:16 +00:00
|
|
|
Annex.Queue.flushWhenFull
|
2012-06-19 06:40:21 +00:00
|
|
|
liftIO $ Just <$> (Change <$> getCurrentTime <*> pure f <*> pure t)
|
|
|
|
|
|
|
|
noChange :: Annex (Maybe Change)
|
|
|
|
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. -}
|
|
|
|
pendingAddChange :: FilePath -> Annex (Maybe Change)
|
|
|
|
pendingAddChange f =
|
|
|
|
liftIO $ Just <$> (PendingAddChange <$> getCurrentTime <*> pure f)
|
2012-06-20 23:04:16 +00:00
|
|
|
|
|
|
|
isPendingAddChange :: Change -> Bool
|
|
|
|
isPendingAddChange (PendingAddChange {}) = True
|
|
|
|
isPendingAddChange _ = False
|
|
|
|
|
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
|
|
|
isInProcessAddChange :: Change -> Bool
|
|
|
|
isInProcessAddChange (InProcessAddChange {}) = True
|
|
|
|
isInProcessAddChange _ = False
|
|
|
|
|
2012-06-20 23:04:16 +00:00
|
|
|
finishedChange :: Change -> Change
|
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
|
|
|
finishedChange c@(InProcessAddChange { keySource = ks }) = Change
|
2012-06-20 23:04:16 +00:00
|
|
|
{ changeTime = changeTime c
|
|
|
|
, changeFile = keyFilename ks
|
|
|
|
, changeType = AddChange
|
|
|
|
}
|
|
|
|
finishedChange c = c
|
|
|
|
|
2012-06-19 06:40:21 +00:00
|
|
|
{- Gets all unhandled changes.
|
|
|
|
- Blocks until at least one change is made. -}
|
|
|
|
getChanges :: ChangeChan -> IO [Change]
|
2012-06-22 17:39:44 +00:00
|
|
|
getChanges = getTSet
|
2012-06-19 06:40:21 +00:00
|
|
|
|
|
|
|
{- Puts unhandled changes back into the channel.
|
|
|
|
- Note: Original order is not preserved. -}
|
|
|
|
refillChanges :: ChangeChan -> [Change] -> IO ()
|
2012-06-22 17:39:44 +00:00
|
|
|
refillChanges = putTSet
|
|
|
|
|
|
|
|
{- Records a change in the channel. -}
|
|
|
|
recordChange :: ChangeChan -> Change -> IO ()
|
|
|
|
recordChange = putTSet1
|