check preferred content when a file is moved or created

This can result in the file being dropped, or being downloaded, or even
being dropped from some other repo.

It's even possible to create a file in a directory where content is not
wanted, which will make the assistant immediately send it elsewhere, and
then drop it.
This commit is contained in:
Joey Hess 2012-10-19 14:22:13 -04:00
parent 168752ca3b
commit f4c3a45da0
2 changed files with 15 additions and 10 deletions

View file

@ -20,6 +20,7 @@ import Assistant.DaemonStatus
import Assistant.Changes import Assistant.Changes
import Assistant.TransferQueue import Assistant.TransferQueue
import Assistant.Alert import Assistant.Alert
import Assistant.Drop
import Logs.Transfer import Logs.Transfer
import Utility.DirWatcher import Utility.DirWatcher
import Utility.Types.DirWatcher import Utility.Types.DirWatcher
@ -135,6 +136,7 @@ onAddSymlink threadname file filestatus dstatus transferqueue = go =<< Backend.l
liftIO $ debug threadname ["fix symlink", file] liftIO $ debug threadname ["fix symlink", file]
liftIO $ removeFile file liftIO $ removeFile file
liftIO $ createSymbolicLink link file liftIO $ createSymbolicLink link file
checkcontent key =<< liftIO (getDaemonStatus dstatus)
addlink link addlink link
) )
go Nothing = do -- other symlink go Nothing = do -- other symlink
@ -146,7 +148,7 @@ onAddSymlink threadname file filestatus dstatus transferqueue = go =<< Backend.l
- and being re-added, or added when the watcher was - and being re-added, or added when the watcher was
- not running. So they're normally restaged to make sure. - not running. So they're normally restaged to make sure.
- -
- As an optimisation, during the status scan, avoid - As an optimisation, during the startup scan, avoid
- restaging everything. Only links that were created since - restaging everything. Only links that were created since
- the last time the daemon was running are staged. - the last time the daemon was running are staged.
- (If the daemon has never ran before, avoid staging - (If the daemon has never ran before, avoid staging
@ -174,12 +176,16 @@ onAddSymlink threadname file filestatus dstatus transferqueue = go =<< Backend.l
stageSymlink file sha stageSymlink file sha
madeChange file LinkChange madeChange file LinkChange
{- When a new link appears, after the startup scan, {- When a new link appears, or a link is changed,
- try to get the key's content. -} - after the startup scan, handle getting or
- dropping the key's content. -}
checkcontent key daemonstatus checkcontent key daemonstatus
| scanComplete daemonstatus = unlessM (inAnnex key) $ | scanComplete daemonstatus = do
queueTransfers Next transferqueue dstatus present <- inAnnex key
key (Just file) Download unless present $
queueTransfers Next transferqueue dstatus
key (Just file) Download
handleDrops dstatus present key (Just file)
| otherwise = noop | otherwise = noop
onDel :: Handler onDel :: Handler

View file

@ -33,10 +33,9 @@ the same content, this gets tricky. Let's assume there are not.)
groups change. Generally, some change to global annex state. Only way to deal groups change. Generally, some change to global annex state. Only way to deal
with this is an expensive scan. (The rest of the items below come from with this is an expensive scan. (The rest of the items below come from
analizing the terminals used in preferred content expressions.) **done** analizing the terminals used in preferred content expressions.) **done**
2. renaming of a file (ie, moved to `archive/`) 2. renaming of a file (ie, moved to `archive/`) **done**
(note that renaming a file can also make it become preferred content (note also that renaming a file can also make it become preferred content
again, and should cause it to be transferred in that case, which doesn't again, and should cause it to be transferred in that case) **done**
happen either..)
3. we get a file (`in`, `copies`) **done** 3. we get a file (`in`, `copies`) **done**
4. we sent a file (`in`, `copies`) **done** 4. we sent a file (`in`, `copies`) **done**
5. some other repository drops the file (`in`, `copies` .. However, it's 5. some other repository drops the file (`in`, `copies` .. However, it's