2012-06-19 06:40:21 +00:00
|
|
|
{- git-annex assistant commit thread
|
2012-06-13 16:36:33 +00:00
|
|
|
-
|
|
|
|
- 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-13 16:36:33 +00:00
|
|
|
-}
|
|
|
|
|
2012-10-04 23:56:32 +00:00
|
|
|
{-# LANGUAGE CPP, BangPatterns #-}
|
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
|
|
|
|
2012-06-25 20:10:10 +00:00
|
|
|
module Assistant.Threads.Committer where
|
2012-06-13 16:36:33 +00:00
|
|
|
|
2012-07-20 23:29:59 +00:00
|
|
|
import Assistant.Common
|
2012-06-19 06:40:21 +00:00
|
|
|
import Assistant.Changes
|
2012-10-29 23:30:23 +00:00
|
|
|
import Assistant.Types.Changes
|
2012-06-22 17:39:44 +00:00
|
|
|
import Assistant.Commits
|
2012-08-02 13:03:04 +00:00
|
|
|
import Assistant.Alert
|
2012-10-30 18:34:48 +00:00
|
|
|
import Assistant.DaemonStatus
|
2012-07-05 16:21:22 +00:00
|
|
|
import Assistant.TransferQueue
|
2013-03-10 22:16:03 +00:00
|
|
|
import Assistant.Drop
|
2012-07-05 16:21:22 +00:00
|
|
|
import Logs.Transfer
|
2013-02-05 17:41:48 +00:00
|
|
|
import Logs.Location
|
2012-06-13 16:36:33 +00:00
|
|
|
import qualified Annex.Queue
|
|
|
|
import qualified Git.Command
|
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
|
|
|
import qualified Git.LsFiles
|
2012-09-19 16:58:53 +00:00
|
|
|
import qualified Git.Version
|
preliminary deferring of file adds to commit time
Defer adding files to the annex until commit time, when during a batch
operation, a bundle of files will be available. This will allow for
checking a them all with a single lsof call.
The tricky part is that adding the file causes a symlink change inotify.
So I made it wait for an appropriate number of symlink changes to be
received before continuing with the commit. This avoids any delay
in the commit process. It is possible that some unrelated symlink change is
made; if that happens it'll commit it and delay committing the newly added
symlink for 1 second. This seems ok. I do rely on the expected symlink
change event always being received, but only when the add succeeds.
Another way to do it might be to directly stage the symlink, and then
ignore the redundant symlink change event. That would involve some
redundant work, and perhaps an empty commit, but if this code turns
out to have some bug, that'd be the best way to avoid it.
FWIW, this change seems to, as a bonus, have produced better grouping
of batch changes into single commits. Before, a large batch change would
result in a series of commits, with the first containing only one file,
and each of the rest bundling a number of files. Now, the added wait for
the symlink changes to arrive gives time for additional add changes to
be processed, all within the same commit.
2012-06-15 20:27:44 +00:00
|
|
|
import qualified Command.Add
|
2012-06-13 21:54:23 +00:00
|
|
|
import Utility.ThreadScheduler
|
2012-06-16 02:35:29 +00:00
|
|
|
import qualified Utility.Lsof as Lsof
|
2012-06-19 06:40:21 +00:00
|
|
|
import qualified Utility.DirWatcher as DirWatcher
|
2012-06-20 20:07:14 +00:00
|
|
|
import Types.KeySource
|
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
|
|
|
import Config
|
2012-10-02 22:04:06 +00:00
|
|
|
import Annex.Exception
|
2012-12-24 17:37:29 +00:00
|
|
|
import Annex.Content
|
fully support core.symlinks=false in all relevant symlink handling code
Refactored annex link code into nice clean new library.
Audited and dealt with calls to createSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ createSymbolicLink linktarget file
only when core.symlinks=true
Assistant/WebApp/Configurators/Local.hs: createSymbolicLink link link
test if symlinks can be made
Command/Fix.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/FromKey.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/Indirect.hs: liftIO $ createSymbolicLink l f
refuses to run if core.symlinks=false
Init.hs: createSymbolicLink f f2
test if symlinks can be made
Remote/Directory.hs: go [file] = catchBoolIO $ createSymbolicLink file f >> return True
fast key linking; catches failure to make symlink and falls back to copy
Remote/Git.hs: liftIO $ catchBoolIO $ createSymbolicLink loc file >> return True
ditto
Upgrade/V1.hs: liftIO $ createSymbolicLink link f
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to readSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ catchMaybeIO $ readSymbolicLink file
only when core.symlinks=true
Assistant/Threads/Watcher.hs: ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file))
code that fixes real symlinks when inotify sees them
It's ok to not fix psdueo-symlinks.
Assistant/Threads/Watcher.hs: mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
ditto
Command/Fix.hs: stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
command only works in indirect mode
Upgrade/V1.hs: getsymlink = takeFileName <$> readSymbolicLink file
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to isSymbolicLink.
(Typically used with getSymbolicLinkStatus, but that is just used because
getFileStatus is not as robust; it also works on pseudolinks.)
Remaining calls are all safe, because:
Assistant/Threads/SanityChecker.hs: | isSymbolicLink s -> addsymlink file ms
only handles staging of symlinks that were somehow not staged
(might need to be updated to support pseudolinks, but this is
only a belt-and-suspenders check anyway, and I've never seen the code run)
Command/Add.hs: if isSymbolicLink s || not (isRegularFile s)
avoids adding symlinks to the annex, so not relevant
Command/Indirect.hs: | isSymbolicLink s -> void $ flip whenAnnexed f $
only allowed on systems that support symlinks
Command/Indirect.hs: whenM (liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f) $ do
ditto
Seek.hs:notSymlink f = liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f
used to find unlocked files, only relevant in indirect mode
Utility/FSEvents.hs: | Files.isSymbolicLink s = runhook addSymlinkHook $ Just s
Utility/FSEvents.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: checkfiletype Files.isSymbolicLink addSymlinkHook f
Utility/Kqueue.hs: | Files.isSymbolicLink s = callhook addSymlinkHook (Just s) change
all above are lower-level, not relevant
Audited and dealt with calls to isSymLink.
Remaining calls are all safe, because:
Annex/Direct.hs: | isSymLink (getmode item) =
This is looking at git diff-tree objects, not files on disk
Command/Unused.hs: | isSymLink (LsTree.mode l) = do
This is looking at git ls-tree, not file on disk
Utility/FileMode.hs:isSymLink :: FileMode -> Bool
Utility/FileMode.hs:isSymLink = checkMode symbolicLinkMode
low-level
Done!!
2013-02-17 19:05:55 +00:00
|
|
|
import Annex.Link
|
2013-03-11 16:56:47 +00:00
|
|
|
import Annex.CatFile
|
2012-12-30 03:10:18 +00:00
|
|
|
import qualified Annex
|
2013-03-11 16:56:47 +00:00
|
|
|
import Utility.InodeCache
|
|
|
|
import Annex.Content.Direct
|
2012-06-13 16:36:33 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock
|
2012-06-16 02:35:29 +00:00
|
|
|
import Data.Tuple.Utils
|
|
|
|
import qualified Data.Set as S
|
2013-03-11 16:56:47 +00:00
|
|
|
import qualified Data.Map as M
|
2012-06-20 23:04:16 +00:00
|
|
|
import Data.Either
|
2013-03-11 01:36:13 +00:00
|
|
|
import Control.Concurrent
|
2012-06-13 16:36:33 +00:00
|
|
|
|
|
|
|
{- This thread makes git commits at appropriate times. -}
|
2012-10-29 15:40:22 +00:00
|
|
|
commitThread :: NamedThread
|
2013-01-26 06:09:33 +00:00
|
|
|
commitThread = namedThread "Committer" $ do
|
2012-12-30 03:10:18 +00:00
|
|
|
delayadd <- liftAnnex $
|
|
|
|
maybe delayaddDefault (return . Just . Seconds)
|
2013-01-01 17:52:47 +00:00
|
|
|
=<< annexDelayAdd <$> Annex.getGitConfig
|
2013-03-11 01:36:13 +00:00
|
|
|
waitChangeTime $ \(changes, time) -> do
|
|
|
|
readychanges <- handleAdds delayadd changes
|
|
|
|
if shouldCommit time readychanges
|
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
|
|
|
then do
|
2013-03-11 01:36:13 +00:00
|
|
|
debug
|
|
|
|
[ "committing"
|
|
|
|
, show (length readychanges)
|
|
|
|
, "changes"
|
|
|
|
]
|
|
|
|
void $ alertWhile commitAlert $
|
|
|
|
liftAnnex commitStaged
|
|
|
|
recordCommit
|
|
|
|
mapM_ checkChangeContent readychanges
|
|
|
|
else refill readychanges
|
|
|
|
|
|
|
|
refill :: [Change] -> Assistant ()
|
|
|
|
refill [] = noop
|
|
|
|
refill cs = do
|
|
|
|
debug ["delaying commit of", show (length cs), "changes"]
|
|
|
|
refillChanges cs
|
|
|
|
|
|
|
|
{- Wait for one or more changes to arrive to be committed. -}
|
|
|
|
waitChangeTime :: (([Change], UTCTime) -> Assistant ()) -> Assistant ()
|
|
|
|
waitChangeTime a = runEvery (Seconds 1) <~> do
|
|
|
|
-- We already waited one second as a simple rate limiter.
|
|
|
|
-- Next, wait until at least one change is available for
|
|
|
|
-- processing.
|
|
|
|
changes <- getChanges
|
|
|
|
-- See if now's a good time to commit.
|
|
|
|
now <- liftIO getCurrentTime
|
|
|
|
case (shouldCommit now changes, lonelychange changes) of
|
|
|
|
(True, False) -> a (changes, now)
|
|
|
|
(True, True) -> do
|
|
|
|
-- Wait for other, related changes to arrive.
|
|
|
|
liftIO $ humanImperceptibleDelay
|
|
|
|
-- Don't block, but are there any?
|
|
|
|
morechanges <- getAnyChanges
|
|
|
|
let allchanges = changes++morechanges
|
|
|
|
a (allchanges, now)
|
|
|
|
_ -> refill changes
|
|
|
|
where
|
|
|
|
{- Did we perhaps only get one of the AddChange and RmChange pair
|
|
|
|
- that make up a rename? -}
|
|
|
|
lonelychange [(PendingAddChange _ _)] = True
|
2013-03-11 16:56:47 +00:00
|
|
|
lonelychange [c] | isRmChange c = True
|
2013-03-11 01:36:13 +00:00
|
|
|
lonelychange _ = False
|
|
|
|
|
2013-03-11 16:56:47 +00:00
|
|
|
isRmChange :: Change -> Bool
|
|
|
|
isRmChange (Change { changeInfo = i }) | i == RmChange = True
|
|
|
|
isRmChange _ = False
|
|
|
|
|
2013-03-11 01:36:13 +00:00
|
|
|
{- An amount of time that is hopefully imperceptably short for humans,
|
|
|
|
- while long enough for a computer to get some work done.
|
|
|
|
- Note that 0.001 is a little too short for rename change batching to
|
|
|
|
- work. -}
|
|
|
|
humanImperceptibleInterval :: NominalDiffTime
|
|
|
|
humanImperceptibleInterval = 0.01
|
|
|
|
|
|
|
|
humanImperceptibleDelay :: IO ()
|
|
|
|
humanImperceptibleDelay = threadDelay $
|
|
|
|
truncate $ humanImperceptibleInterval * fromIntegral oneSecond
|
|
|
|
|
|
|
|
{- Decide if now is a good time to make a commit.
|
|
|
|
- Note that the list of changes has an undefined order.
|
|
|
|
-
|
|
|
|
- Current strategy: If there have been 10 changes within the past second,
|
|
|
|
- a batch activity is taking place, so wait for later.
|
|
|
|
-}
|
|
|
|
shouldCommit :: UTCTime -> [Change] -> Bool
|
|
|
|
shouldCommit now changes
|
|
|
|
| len == 0 = False
|
|
|
|
| len > 10000 = True -- avoid bloating queue too much
|
|
|
|
| length recentchanges < 10 = True
|
|
|
|
| otherwise = False -- batch activity
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
2013-03-11 01:36:13 +00:00
|
|
|
len = length changes
|
|
|
|
thissecond c = timeDelta c <= 1
|
|
|
|
recentchanges = filter thissecond changes
|
|
|
|
timeDelta c = now `diffUTCTime` changeTime c
|
2012-06-13 16:36:33 +00:00
|
|
|
|
run current branch merge in annex monad
I was seeing some interesting crashes after the previous commit,
when making file changes slightly faster than the assistant could keep up.
error: Ref refs/heads/master is at 7074f8e0a11110c532d06746e334f2fec6af6ab4 but expected 95ea86008d72a40d97a81cfc8fb47a0da92166bd
fatal: cannot lock HEAD ref
Committer crashed: git commit [Param "--allow-empty-message",Param "-m",Param "",Param "--allow-empty",Param "--quiet"] failed
Pusher crashed: thread blocked indefinitely in an STM transaction
Clearly the the merger ended up running at the same time as the committer,
and with both modifying HEAD the committer crashed. I fixed that by
making the Merger run its merge inside the annex monad, which avoids
it running concurrently with other git operations. Also by making
the committer not crash if git fails.
What I don't understand is why the pusher then crashed with a STM deadlock.
That must be in either the DaemonStatusHandle or the FailedPushMap,
and the latter is only used by the pusher. Did the committer's crash somehow
break STM?
The BlockedIndefinitelyOnSTM exception is described as:
-- |The thread is waiting to retry an STM transaction, but there are no
-- other references to any @TVar@s involved, so it can't ever continue.
If the Committer had a reference to a TVar and crashed, I can sort of see
this leading to that exception..
The crash was quite easy to reproduce after the previous commit, but
after making the above change, I have yet to see it again. Here's hoping.
2012-09-18 01:32:30 +00:00
|
|
|
commitStaged :: Annex Bool
|
2012-06-13 16:36:33 +00:00
|
|
|
commitStaged = do
|
2012-10-02 22:04:06 +00:00
|
|
|
{- This could fail if there's another commit being made by
|
|
|
|
- something else. -}
|
|
|
|
v <- tryAnnex Annex.Queue.flush
|
|
|
|
case v of
|
|
|
|
Left _ -> return False
|
|
|
|
Right _ -> do
|
2013-02-06 16:40:59 +00:00
|
|
|
direct <- isDirect
|
2013-03-03 17:39:07 +00:00
|
|
|
let params = nomessage $ catMaybes
|
2013-03-03 19:18:24 +00:00
|
|
|
[ Just $ Param "--quiet"
|
2013-02-06 16:40:59 +00:00
|
|
|
{- In indirect mode, avoid running the
|
|
|
|
- usual git-annex pre-commit hook;
|
|
|
|
- watch does the same symlink fixing,
|
|
|
|
- and we don't want to deal with unlocked
|
|
|
|
- files in these commits. -}
|
|
|
|
, if direct then Nothing else Just $ Param "--no-verify"
|
2012-10-02 22:04:06 +00:00
|
|
|
]
|
|
|
|
{- Empty commits may be made if tree changes cancel
|
|
|
|
- each other out, etc. Git returns nonzero on those,
|
|
|
|
- so don't propigate out commit failures. -}
|
2013-03-01 20:21:29 +00:00
|
|
|
void $ inRepo $ catchMaybeIO .
|
2013-03-03 19:18:24 +00:00
|
|
|
Git.Command.runQuiet (Param "commit" : params)
|
2012-10-02 22:04:06 +00:00
|
|
|
return True
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
nomessage ps
|
|
|
|
| Git.Version.older "1.7.2" = Param "-m"
|
|
|
|
: Param "autocommit" : ps
|
|
|
|
| otherwise = Param "--allow-empty-message"
|
|
|
|
: Param "-m" : Param "" : ps
|
2012-06-13 16:36:33 +00:00
|
|
|
|
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
|
|
|
{- OSX needs a short delay after a file is added before locking it down,
|
2012-12-28 20:42:11 +00:00
|
|
|
- when using a non-direct mode repository, as pasting a file seems to
|
|
|
|
- try to set file permissions or otherwise access the file after closing
|
|
|
|
- it. -}
|
|
|
|
delayaddDefault :: Annex (Maybe Seconds)
|
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
|
|
|
#ifdef darwin_HOST_OS
|
2012-12-28 20:42:11 +00:00
|
|
|
delayaddDefault = ifM isDirect
|
|
|
|
( return Nothing
|
|
|
|
, return $ Just $ Seconds 1
|
|
|
|
)
|
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
|
|
|
#else
|
2012-12-28 20:42:11 +00:00
|
|
|
delayaddDefault = 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
|
|
|
#endif
|
|
|
|
|
|
|
|
{- If there are PendingAddChanges, or InProcessAddChanges, the files
|
|
|
|
- have not yet actually been added to the annex, and that has to be done
|
|
|
|
- now, before committing.
|
2012-06-16 00:44:34 +00:00
|
|
|
-
|
|
|
|
- Deferring the adds to this point causes batches to be bundled together,
|
|
|
|
- which allows faster checking with lsof that the files are not still open
|
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
|
|
|
- for write by some other process, and faster checking with git-ls-files
|
|
|
|
- that the files are not already checked into git.
|
2012-06-16 00:44:34 +00:00
|
|
|
-
|
|
|
|
- When a file is added, Inotify will notice the new symlink. So this waits
|
|
|
|
- for additional Changes to arrive, so that the symlink has hopefully been
|
2012-06-20 20:07:14 +00:00
|
|
|
- staged before returning, and will be committed immediately.
|
|
|
|
-
|
|
|
|
- OTOH, for kqueue, eventsCoalesce, so instead the symlink is directly
|
2012-06-20 23:04:16 +00:00
|
|
|
- created and staged.
|
|
|
|
-
|
|
|
|
- Returns a list of all changes that are ready to be committed.
|
|
|
|
- Any pending adds that are not ready yet are put back into the ChangeChan,
|
|
|
|
- where they will be retried later.
|
2012-06-16 00:44:34 +00:00
|
|
|
-}
|
2012-10-29 15:40:22 +00:00
|
|
|
handleAdds :: Maybe Seconds -> [Change] -> Assistant [Change]
|
|
|
|
handleAdds delayadd cs = returnWhen (null incomplete) $ do
|
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
|
|
|
let (pending, inprocess) = partition isPendingAddChange incomplete
|
2012-12-24 18:42:19 +00:00
|
|
|
direct <- liftAnnex isDirect
|
|
|
|
pending' <- if direct
|
|
|
|
then return pending
|
|
|
|
else findnew pending
|
2012-10-29 15:40:22 +00:00
|
|
|
(postponed, toadd) <- partitionEithers <$> safeToAdd delayadd pending' inprocess
|
2012-06-20 23:04:16 +00:00
|
|
|
|
|
|
|
unless (null postponed) $
|
2012-10-29 23:30:23 +00:00
|
|
|
refillChanges postponed
|
2012-06-20 23:04:16 +00:00
|
|
|
|
|
|
|
returnWhen (null toadd) $ do
|
2013-03-11 16:56:47 +00:00
|
|
|
added <- catMaybes <$> if direct
|
|
|
|
then adddirect toadd
|
|
|
|
else forM toadd add
|
2012-12-24 17:37:29 +00:00
|
|
|
if DirWatcher.eventsCoalesce || null added || direct
|
2012-06-20 23:04:16 +00:00
|
|
|
then return $ added ++ otherchanges
|
|
|
|
else do
|
2012-10-29 23:30:23 +00:00
|
|
|
r <- handleAdds delayadd =<< getChanges
|
2012-06-20 23:04:16 +00:00
|
|
|
return $ r ++ added ++ otherchanges
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
(incomplete, otherchanges) = partition (\c -> isPendingAddChange c || isInProcessAddChange c) cs
|
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
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
findnew [] = return []
|
|
|
|
findnew pending@(exemplar:_) = do
|
|
|
|
(!newfiles, cleanup) <- liftAnnex $
|
|
|
|
inRepo (Git.LsFiles.notInRepo False $ map changeFile pending)
|
|
|
|
void $ liftIO cleanup
|
|
|
|
-- note: timestamp info is lost here
|
|
|
|
let ts = changeTime exemplar
|
|
|
|
return $ map (PendingAddChange ts) newfiles
|
|
|
|
|
|
|
|
returnWhen c a
|
|
|
|
| c = return otherchanges
|
|
|
|
| otherwise = a
|
2012-06-20 23:04:16 +00:00
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
add :: Change -> Assistant (Maybe Change)
|
|
|
|
add change@(InProcessAddChange { keySource = ks }) = do
|
2012-10-29 20:49:47 +00:00
|
|
|
alertWhile' (addFileAlert $ keyFilename ks) $
|
|
|
|
liftM ret $ catchMaybeIO <~> do
|
|
|
|
sanitycheck ks $ do
|
|
|
|
key <- liftAnnex $ do
|
|
|
|
showStart "add" $ keyFilename ks
|
2013-01-14 19:02:13 +00:00
|
|
|
Command.Add.ingest $ Just ks
|
2013-03-10 22:16:03 +00:00
|
|
|
maybe failedingest (done change $ keyFilename ks) key
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
{- Add errors tend to be transient and will be automatically
|
|
|
|
- dealt with, so don't pass to the alert code. -}
|
|
|
|
ret (Just j@(Just _)) = (True, j)
|
|
|
|
ret _ = (True, Nothing)
|
2012-10-29 20:49:47 +00:00
|
|
|
add _ = return Nothing
|
2012-06-16 00:44:34 +00:00
|
|
|
|
2013-03-11 16:56:47 +00:00
|
|
|
{- In direct mode, avoid overhead of re-injesting a renamed
|
|
|
|
- file, by examining the other Changes to see if a removed
|
|
|
|
- file has the same InodeCache as the new file. If so,
|
|
|
|
- we can just update bookkeeping, and stage the file in git.
|
|
|
|
-}
|
|
|
|
adddirect :: [Change] -> Assistant [Maybe Change]
|
|
|
|
adddirect toadd = do
|
|
|
|
ct <- liftAnnex compareInodeCachesWith
|
|
|
|
m <- liftAnnex $ removedKeysMap ct cs
|
|
|
|
if M.null m
|
|
|
|
then forM toadd add
|
|
|
|
else forM toadd $ \c -> do
|
|
|
|
mcache <- liftIO $ genInodeCache $ changeFile c
|
|
|
|
case mcache of
|
|
|
|
Nothing -> add c
|
|
|
|
Just cache ->
|
|
|
|
case M.lookup (inodeCacheToKey ct cache) m of
|
|
|
|
Nothing -> add c
|
|
|
|
Just k -> fastadd c k cache
|
|
|
|
|
|
|
|
fastadd :: Change -> Key -> InodeCache -> Assistant (Maybe Change)
|
|
|
|
fastadd change key cache = do
|
|
|
|
-- TODO do fast method
|
|
|
|
debug ["rename detected", show change, show key, show cache]
|
|
|
|
add change
|
|
|
|
--return $ Just $ finishedChange change key
|
|
|
|
|
|
|
|
removedKeysMap :: InodeComparisonType -> [Change] -> Annex (M.Map InodeCacheKey Key)
|
|
|
|
removedKeysMap ct l = do
|
|
|
|
mks <- forM (filter isRmChange l) $ \c ->
|
|
|
|
catKeyFile $ changeFile c
|
|
|
|
M.fromList . catMaybes <$> forM (catMaybes mks) mkpair
|
|
|
|
where
|
|
|
|
mkpair k = do
|
|
|
|
mcache <- recordedInodeCache k
|
|
|
|
case mcache of
|
|
|
|
Just cache -> return $ Just (inodeCacheToKey ct cache, k)
|
|
|
|
Nothing -> return Nothing
|
|
|
|
|
2013-03-10 22:16:03 +00:00
|
|
|
failedingest = do
|
2012-10-29 15:40:22 +00:00
|
|
|
liftAnnex showEndFail
|
|
|
|
return Nothing
|
2013-03-10 22:16:03 +00:00
|
|
|
|
|
|
|
done change file key = do
|
2013-02-05 17:41:48 +00:00
|
|
|
liftAnnex $ do
|
|
|
|
logStatus key InfoPresent
|
|
|
|
link <- ifM isDirect
|
|
|
|
( calcGitLink file key
|
|
|
|
, Command.Add.link file key True
|
|
|
|
)
|
|
|
|
whenM (pure DirWatcher.eventsCoalesce <||> isDirect) $ do
|
fully support core.symlinks=false in all relevant symlink handling code
Refactored annex link code into nice clean new library.
Audited and dealt with calls to createSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ createSymbolicLink linktarget file
only when core.symlinks=true
Assistant/WebApp/Configurators/Local.hs: createSymbolicLink link link
test if symlinks can be made
Command/Fix.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/FromKey.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/Indirect.hs: liftIO $ createSymbolicLink l f
refuses to run if core.symlinks=false
Init.hs: createSymbolicLink f f2
test if symlinks can be made
Remote/Directory.hs: go [file] = catchBoolIO $ createSymbolicLink file f >> return True
fast key linking; catches failure to make symlink and falls back to copy
Remote/Git.hs: liftIO $ catchBoolIO $ createSymbolicLink loc file >> return True
ditto
Upgrade/V1.hs: liftIO $ createSymbolicLink link f
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to readSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ catchMaybeIO $ readSymbolicLink file
only when core.symlinks=true
Assistant/Threads/Watcher.hs: ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file))
code that fixes real symlinks when inotify sees them
It's ok to not fix psdueo-symlinks.
Assistant/Threads/Watcher.hs: mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
ditto
Command/Fix.hs: stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
command only works in indirect mode
Upgrade/V1.hs: getsymlink = takeFileName <$> readSymbolicLink file
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to isSymbolicLink.
(Typically used with getSymbolicLinkStatus, but that is just used because
getFileStatus is not as robust; it also works on pseudolinks.)
Remaining calls are all safe, because:
Assistant/Threads/SanityChecker.hs: | isSymbolicLink s -> addsymlink file ms
only handles staging of symlinks that were somehow not staged
(might need to be updated to support pseudolinks, but this is
only a belt-and-suspenders check anyway, and I've never seen the code run)
Command/Add.hs: if isSymbolicLink s || not (isRegularFile s)
avoids adding symlinks to the annex, so not relevant
Command/Indirect.hs: | isSymbolicLink s -> void $ flip whenAnnexed f $
only allowed on systems that support symlinks
Command/Indirect.hs: whenM (liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f) $ do
ditto
Seek.hs:notSymlink f = liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f
used to find unlocked files, only relevant in indirect mode
Utility/FSEvents.hs: | Files.isSymbolicLink s = runhook addSymlinkHook $ Just s
Utility/FSEvents.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: checkfiletype Files.isSymbolicLink addSymlinkHook f
Utility/Kqueue.hs: | Files.isSymbolicLink s = callhook addSymlinkHook (Just s) change
all above are lower-level, not relevant
Audited and dealt with calls to isSymLink.
Remaining calls are all safe, because:
Annex/Direct.hs: | isSymLink (getmode item) =
This is looking at git diff-tree objects, not files on disk
Command/Unused.hs: | isSymLink (LsTree.mode l) = do
This is looking at git ls-tree, not file on disk
Utility/FileMode.hs:isSymLink :: FileMode -> Bool
Utility/FileMode.hs:isSymLink = checkMode symbolicLinkMode
low-level
Done!!
2013-02-17 19:05:55 +00:00
|
|
|
stageSymlink file =<< hashSymlink link
|
2013-02-05 17:41:48 +00:00
|
|
|
showEndOk
|
2013-03-10 22:16:03 +00:00
|
|
|
return $ Just $ finishedChange change key
|
2012-06-16 02:35:29 +00:00
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
{- Check that the keysource's keyFilename still exists,
|
|
|
|
- and is still a hard link to its contentLocation,
|
|
|
|
- before ingesting it. -}
|
|
|
|
sanitycheck keysource a = do
|
|
|
|
fs <- liftIO $ getSymbolicLinkStatus $ keyFilename keysource
|
|
|
|
ks <- liftIO $ getSymbolicLinkStatus $ contentLocation keysource
|
|
|
|
if deviceID ks == deviceID fs && fileID ks == fileID fs
|
|
|
|
then a
|
2012-11-29 20:46:59 +00:00
|
|
|
else do
|
|
|
|
-- remove the hard link
|
2013-02-14 18:10:36 +00:00
|
|
|
when (contentLocation keysource /= keyFilename keysource) $
|
|
|
|
void $ liftIO $ tryIO $ removeFile $ contentLocation keysource
|
2012-11-29 20:46:59 +00:00
|
|
|
return Nothing
|
2012-06-21 00:05:40 +00:00
|
|
|
|
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
|
|
|
{- Files can Either be Right to be added now,
|
2012-06-20 23:04:16 +00:00
|
|
|
- or are unsafe, and must be Left for later.
|
|
|
|
-
|
2013-02-15 17:08:22 +00:00
|
|
|
- Check by running lsof on the repository.
|
2012-06-16 02:35:29 +00:00
|
|
|
-}
|
2012-10-29 15:40:22 +00:00
|
|
|
safeToAdd :: Maybe Seconds -> [Change] -> [Change] -> Assistant [Either Change Change]
|
|
|
|
safeToAdd _ [] [] = return []
|
|
|
|
safeToAdd delayadd pending inprocess = do
|
|
|
|
maybe noop (liftIO . threadDelaySeconds) delayadd
|
|
|
|
liftAnnex $ do
|
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
|
|
|
keysources <- mapM Command.Add.lockDown (map changeFile pending)
|
2013-02-15 17:08:22 +00:00
|
|
|
let inprocess' = inprocess ++ catMaybes (map mkinprocess $ zip pending keysources)
|
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
|
|
|
openfiles <- S.fromList . map fst3 . filter openwrite <$>
|
2013-02-15 17:08:22 +00:00
|
|
|
findopenfiles (map keySource inprocess')
|
|
|
|
let checked = map (check openfiles) inprocess'
|
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
|
|
|
|
|
|
|
{- If new events are received when files are closed,
|
|
|
|
- there's no need to retry any changes that cannot
|
|
|
|
- be done now. -}
|
|
|
|
if DirWatcher.closingTracked
|
|
|
|
then do
|
|
|
|
mapM_ canceladd $ lefts checked
|
|
|
|
allRight $ rights checked
|
|
|
|
else return checked
|
2012-10-29 15:40:22 +00:00
|
|
|
where
|
|
|
|
check openfiles change@(InProcessAddChange { keySource = ks })
|
|
|
|
| S.member (contentLocation ks) openfiles = Left change
|
|
|
|
check _ change = Right change
|
2012-06-20 23:04:16 +00:00
|
|
|
|
2013-01-14 19:02:13 +00:00
|
|
|
mkinprocess (c, Just ks) = Just $ InProcessAddChange
|
2012-10-29 15:40:22 +00:00
|
|
|
{ changeTime = changeTime c
|
|
|
|
, keySource = ks
|
|
|
|
}
|
2013-01-14 19:02:13 +00:00
|
|
|
mkinprocess (_, Nothing) = 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
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
canceladd (InProcessAddChange { keySource = ks }) = do
|
|
|
|
warning $ keyFilename ks
|
|
|
|
++ " still has writers, not adding"
|
|
|
|
-- remove the hard link
|
2013-02-14 18:10:36 +00:00
|
|
|
when (contentLocation ks /= keyFilename ks) $
|
|
|
|
void $ liftIO $ tryIO $ removeFile $ contentLocation ks
|
2012-10-29 15:40:22 +00:00
|
|
|
canceladd _ = noop
|
2012-06-16 02:35:29 +00:00
|
|
|
|
2013-02-11 21:24:12 +00:00
|
|
|
openwrite (_file, mode, _pid)
|
|
|
|
| mode == Lsof.OpenWriteOnly = True
|
|
|
|
| mode == Lsof.OpenReadWrite = True
|
|
|
|
| mode == Lsof.OpenUnknown = True
|
|
|
|
| otherwise = False
|
2012-06-20 23:04:16 +00:00
|
|
|
|
2012-10-29 15:40:22 +00:00
|
|
|
allRight = return . map Right
|
2013-02-15 17:08:22 +00:00
|
|
|
|
|
|
|
{- Normally the KeySources are locked down inside the temp directory,
|
|
|
|
- so can just lsof that, which is quite efficient.
|
|
|
|
-
|
|
|
|
- In crippled filesystem mode, there is no lock down, so must run lsof
|
|
|
|
- on each individual file.
|
|
|
|
-}
|
|
|
|
findopenfiles keysources = ifM crippledFileSystem
|
|
|
|
( liftIO $ do
|
|
|
|
let segments = segmentXargs $ map keyFilename keysources
|
|
|
|
concat <$> forM segments (\fs -> Lsof.query $ "--" : fs)
|
|
|
|
, do
|
|
|
|
tmpdir <- fromRepo gitAnnexTmpDir
|
|
|
|
liftIO $ Lsof.queryDir tmpdir
|
|
|
|
)
|
2013-03-10 22:16:03 +00:00
|
|
|
|
|
|
|
{- After a Change is committed, queue any necessary transfers or drops
|
|
|
|
- of the content of the key.
|
|
|
|
-
|
|
|
|
- This is not done during the startup scan, because the expensive
|
|
|
|
- transfer scan does the same thing then.
|
|
|
|
-}
|
|
|
|
checkChangeContent :: Change -> Assistant ()
|
2013-03-11 17:52:06 +00:00
|
|
|
checkChangeContent change@(Change { changeInfo = i }) =
|
2013-03-10 22:16:03 +00:00
|
|
|
case changeInfoKey i of
|
|
|
|
Nothing -> noop
|
|
|
|
Just k -> whenM (scanComplete <$> getDaemonStatus) $ do
|
|
|
|
present <- liftAnnex $ inAnnex k
|
|
|
|
if present
|
|
|
|
then queueTransfers "new file created" Next k (Just f) Upload
|
|
|
|
else queueTransfers "new or renamed file wanted" Next k (Just f) Download
|
|
|
|
handleDrops "file renamed" present k (Just f) Nothing
|
2013-03-11 17:52:06 +00:00
|
|
|
where
|
|
|
|
f = changeFile change
|
2013-03-10 22:16:03 +00:00
|
|
|
checkChangeContent _ = noop
|