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
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
import System.Posix.Files
|
|
|
|
import System.Directory
|
2011-01-26 04:17:38 +00:00
|
|
|
import Control.Monad (unless)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
import Command
|
2011-04-07 17:59:31 +00:00
|
|
|
import qualified AnnexQueue
|
2010-11-02 23:04:24 +00:00
|
|
|
import Utility
|
|
|
|
import qualified Backend
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "fromkey" paramPath seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"adds a file using a specific key"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withFilesMissing start]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2011-03-03 20:40:55 +00:00
|
|
|
start file = notBareRepo $ do
|
2011-01-26 04:17:38 +00:00
|
|
|
key <- cmdlineKey
|
2010-11-02 23:04:24 +00:00
|
|
|
inbackend <- Backend.hasKey key
|
2010-11-22 21:51:55 +00:00
|
|
|
unless inbackend $ error $
|
2011-01-26 04:17:38 +00:00
|
|
|
"key ("++keyName key++") is not present in backend"
|
2010-11-02 23:04:24 +00:00
|
|
|
showStart "fromkey" file
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ perform file
|
2011-01-26 04:17:38 +00:00
|
|
|
|
|
|
|
perform :: FilePath -> CommandPerform
|
|
|
|
perform file = do
|
|
|
|
key <- cmdlineKey
|
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
|
2011-04-07 17:59:31 +00:00
|
|
|
AnnexQueue.add "add" [Param "--"] file
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|