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