2010-11-02 19:04:24 -04:00
|
|
|
{- 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 16:02:51 -04:00
|
|
|
import Common.Annex
|
2010-11-02 19:04:24 -04:00
|
|
|
import Command
|
2011-10-04 00:40:47 -04:00
|
|
|
import qualified Annex.Queue
|
|
|
|
import Annex.Content
|
2011-06-01 21:56:04 -04:00
|
|
|
import Types.Key
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-10-29 15:19:05 -04:00
|
|
|
def :: [Command]
|
2011-10-31 12:47:13 -04:00
|
|
|
def = [command "fromkey" (paramPair paramKey paramPath) seek
|
|
|
|
"adds a file using a specific key"]
|
2010-12-30 15:06:26 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
seek :: [CommandSeek]
|
2011-10-31 12:47:13 -04:00
|
|
|
seek = [withWords start]
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2011-10-31 12:47:13 -04:00
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start (keyname:file:[]) = notBareRepo $ do
|
2011-11-11 01:52:58 -04:00
|
|
|
let key = fromMaybe (error "bad key") $ readKey keyname
|
2011-07-05 18:31:46 -04:00
|
|
|
inbackend <- inAnnex key
|
2010-11-22 17:51:55 -04:00
|
|
|
unless inbackend $ error $
|
2011-10-31 12:47:13 -04:00
|
|
|
"key ("++ keyname ++") is not present in backend"
|
2010-11-02 19:04:24 -04:00
|
|
|
showStart "fromkey" file
|
2011-10-31 12:47:13 -04:00
|
|
|
next $ perform key file
|
|
|
|
start _ = error "specify a key and a dest file"
|
2011-01-26 00:17:38 -04:00
|
|
|
|
2011-10-31 12:47:13 -04:00
|
|
|
perform :: Key -> FilePath -> CommandPerform
|
|
|
|
perform key file = do
|
2010-11-02 19:04:24 -04:00
|
|
|
link <- calcGitLink file key
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
|
|
|
liftIO $ createSymbolicLink link file
|
2011-05-15 02:02:46 -04:00
|
|
|
next $ cleanup file
|
2011-01-26 00:17:38 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
cleanup :: FilePath -> CommandCleanup
|
2010-11-02 19:04:24 -04:00
|
|
|
cleanup file = do
|
2011-10-04 00:40:47 -04:00
|
|
|
Annex.Queue.add "add" [Param "--"] [file]
|
2010-11-02 19:04:24 -04:00
|
|
|
return True
|