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.SetKey where
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
import Control.Monad (when)
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
|
|
|
import Utility
|
|
|
|
import qualified Backend
|
|
|
|
import LocationLog
|
|
|
|
import Types
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
|
|
|
command = [Command "setkey" (paramRepeating paramKey) seek
|
|
|
|
"sets annexed content for a key using a temp file"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withTempFile start]
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- Sets cached content for a key. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2010-11-08 23:26:37 +00:00
|
|
|
start file = do
|
2010-11-02 23:04:24 +00:00
|
|
|
keyname <- Annex.flagGet "key"
|
|
|
|
when (null keyname) $ error "please specify the key with --key"
|
|
|
|
backends <- Backend.list
|
2010-11-22 21:51:55 +00:00
|
|
|
let key = genKey (head backends) keyname
|
2010-11-08 23:26:37 +00:00
|
|
|
showStart "setkey" file
|
|
|
|
return $ Just $ perform file key
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2010-11-08 23:26:37 +00:00
|
|
|
perform file key = do
|
|
|
|
-- the file might be on a different filesystem, so mv is used
|
|
|
|
-- rather than simply calling moveToObjectDir key file
|
2010-11-27 21:07:22 +00:00
|
|
|
ok <- getViaTmp key $ \dest -> do
|
|
|
|
if dest /= file
|
|
|
|
then liftIO $ boolSystem "mv" [file, dest]
|
|
|
|
else return True
|
2010-11-08 23:26:37 +00:00
|
|
|
if ok
|
|
|
|
then return $ Just $ cleanup key
|
|
|
|
else error "mv failed!"
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup key = do
|
|
|
|
logStatus key ValuePresent
|
|
|
|
return True
|
|
|
|
|