summaryrefslogtreecommitdiff
path: root/Command/Watch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-04 15:10:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-04 15:10:43 -0400
commit677ad7468700ae77cbf66a18d047de011b2d173d (patch)
tree58f20c93dbebff8d5ac14d8d333cc6b752e01966 /Command/Watch.hs
parent47f8f43715f355e141fc2d57ce7f72bdda75b5d6 (diff)
add handling of symlink addition events
And just like that, annexed files can be moved and copies around within the tree, and are automatically fixed to point to the content, and staged in git. Huzzah! Delete still remains TODO, with its troublesome race during add..
Diffstat (limited to 'Command/Watch.hs')
-rw-r--r--Command/Watch.hs44
1 files changed, 36 insertions, 8 deletions
diff --git a/Command/Watch.hs b/Command/Watch.hs
index abbc98ad5..0f60bd636 100644
--- a/Command/Watch.hs
+++ b/Command/Watch.hs
@@ -7,15 +7,18 @@
module Command.Watch where
+import CmdLine
import Common.Annex
import Command
-import qualified Annex
-import CmdLine
import Utility.Inotify
-import Control.Exception as E
+import qualified Annex
import qualified Command.Add as Add
import qualified Git.Command
+import qualified Annex.Queue
+import qualified Backend
+import Annex.Content
+import Control.Exception as E
import System.INotify
def :: [Command]
@@ -55,16 +58,41 @@ run startstate a f = do
_ <- shutdown True
return ()
+{- Adding a file is the same as git-annex add.
+ - The git queue is immediately flushed, so the file is added to git
+ - now, rather than later (when it may have been already moved or deleted!) -}
onAdd :: FilePath -> Annex ()
-onAdd file = void $ doCommand $ do
- showStart "add" file
- next $ Add.perform file
+onAdd file = do
+ void $ doCommand $ do
+ showStart "add" file
+ next $ Add.perform file
+ Annex.Queue.flush
+{- A symlink might be an arbitrary symlink, which is just added.
+ - Or, if it is a git-annex symlink, ensure it points to the content
+ - before adding it.
+ -}
onAddSymlink :: FilePath -> Annex ()
-onAddSymlink link = liftIO $ print $ "add symlink " ++ link
+onAddSymlink file = go =<< Backend.lookupFile file
+ where
+ go Nothing = addlink
+ go (Just (key, _)) = do
+ link <- calcGitLink file key
+ ifM ((==) link <$> liftIO (readSymbolicLink file))
+ ( addlink
+ , do
+ liftIO $ removeFile file
+ liftIO $ createSymbolicLink link file
+ addlink
+ )
+ addlink = inRepo $ Git.Command.run "add"
+ [Params "--force --", File file]
onDel :: FilePath -> Annex ()
onDel file = liftIO $ print $ "del " ++ file
+{- A directory has been deleted, so tell git to remove anything that
+ was inside it from its cache. -}
onDelDir :: FilePath -> Annex ()
-onDelDir dir = inRepo $ Git.Command.run "rm" [Params "--quiet -r", File dir]
+onDelDir dir = inRepo $ Git.Command.run "rm"
+ [Params "--quiet -r --cached --", File dir]