git-annex/Command/FromKey.hs

44 lines
1.1 KiB
Haskell
Raw Normal View History

{- git-annex command
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.FromKey where
2011-10-05 20:02:51 +00:00
import Common.Annex
import Command
2011-10-04 04:40:47 +00:00
import qualified Annex.Queue
import Annex.Content
import Types.Key
def :: [Command]
def = [command "fromkey" (paramPair paramKey paramPath) seek
"adds a file using a specific key"]
seek :: [CommandSeek]
seek = [withWords start]
2010-11-11 22:54:52 +00:00
start :: [String] -> CommandStart
start (keyname:file:[]) = notBareRepo $ do
2011-11-11 05:52:58 +00:00
let key = fromMaybe (error "bad key") $ readKey keyname
inbackend <- inAnnex key
2010-11-22 21:51:55 +00:00
unless inbackend $ error $
"key ("++ keyname ++") is not present in backend"
showStart "fromkey" file
next $ perform key file
start _ = error "specify a key and a dest file"
perform :: Key -> FilePath -> CommandPerform
perform key file = do
link <- calcGitLink file key
liftIO $ createDirectoryIfMissing True (parentDir file)
liftIO $ createSymbolicLink link file
2011-05-15 06:02:46 +00:00
next $ cleanup file
cleanup :: FilePath -> CommandCleanup
cleanup file = do
2011-10-04 04:40:47 +00:00
Annex.Queue.add "add" [Param "--"] [file]
return True