diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-12-15 15:34:28 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-12-15 15:34:28 -0400 |
commit | 59654d08a2335bf716f38b76095121c6e4c62535 (patch) | |
tree | f4d450caa09cfc4e373ee946b2cef956f9429757 /Annex/WorkTree.hs | |
parent | 271fe1ce457447b0aee8d825b9186a0b579b56d0 (diff) |
reorg
Diffstat (limited to 'Annex/WorkTree.hs')
-rw-r--r-- | Annex/WorkTree.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Annex/WorkTree.hs b/Annex/WorkTree.hs new file mode 100644 index 000000000..26144e7f9 --- /dev/null +++ b/Annex/WorkTree.hs @@ -0,0 +1,35 @@ +{- git-annex worktree files + - + - Copyright 2013-2015 Joey Hess <id@joeyh.name> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Annex.WorkTree where + +import Common.Annex +import Annex.Link +import Annex.CatFile + +{- Looks up the key corresponding to an annexed file, + - by examining what the file links to. + - + - An unlocked file will not have a link on disk, so fall back to + - looking for a pointer to a key in git. + -} +lookupFile :: FilePath -> Annex (Maybe Key) +lookupFile file = do + mkey <- isAnnexLink file + case mkey of + Just key -> makeret key + Nothing -> maybe (return Nothing) makeret =<< catKeyFile file + where + makeret = return . Just + +{- Modifies an action to only act on files that are already annexed, + - and passes the key on to it. -} +whenAnnexed :: (FilePath -> Key -> Annex (Maybe a)) -> FilePath -> Annex (Maybe a) +whenAnnexed a file = ifAnnexed file (a file) (return Nothing) + +ifAnnexed :: FilePath -> (Key -> Annex a) -> Annex a -> Annex a +ifAnnexed file yes no = maybe no yes =<< lookupFile file |