moved transfer queueing out of watcher and into committer

This cleaned up the code quite a bit; now the committer just looks at the
Change to see if it's a change that needs to have a transfer queued for it.
If I later want to add dropping keys for files that were removed, or
something like that, this should make it straightforward.

This also fixes a bug. In direct mode, moving a file out of an archive
directory failed to start a transfer to get its content. The problem
was that the file had not been committed to git yet, and so the transfer
code didn't want to touch it, since fileKey failed to get its key.
Only starting transfers after a commit avoids this problem.
This commit is contained in:
Joey Hess 2013-03-10 18:16:03 -04:00
parent 69ab9701eb
commit 65a4c7966f
5 changed files with 50 additions and 43 deletions

View file

@ -8,20 +8,26 @@
module Assistant.Types.Changes where
import Types.KeySource
import Types.Key
import Utility.TSet
import Data.Time.Clock
data ChangeType = AddChange | LinkChange | RmChange | RmDirChange
data ChangeInfo = AddChange Key | LinkChange (Maybe Key) | RmChange | RmDirChange
deriving (Show, Eq)
changeInfoKey :: ChangeInfo -> Maybe Key
changeInfoKey (AddChange k) = Just k
changeInfoKey (LinkChange (Just k)) = Just k
changeInfoKey _ = Nothing
type ChangeChan = TSet Change
data Change
= Change
{ changeTime :: UTCTime
, changeFile :: FilePath
, changeType :: ChangeType
, changeInfo :: ChangeInfo
}
| PendingAddChange
{ changeTime ::UTCTime
@ -44,11 +50,10 @@ isInProcessAddChange :: Change -> Bool
isInProcessAddChange (InProcessAddChange {}) = True
isInProcessAddChange _ = False
finishedChange :: Change -> Change
finishedChange c@(InProcessAddChange { keySource = ks }) = Change
finishedChange :: Change -> Key -> Change
finishedChange c@(InProcessAddChange { keySource = ks }) k = Change
{ changeTime = changeTime c
, changeFile = keyFilename ks
, changeType = AddChange
, changeInfo = AddChange k
}
finishedChange c = c
finishedChange c _ = c