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 Command
|
|
|
|
import Utility
|
|
|
|
import LocationLog
|
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]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "setkey" (paramRepeating paramKey) seek
|
2010-12-30 19:06:26 +00:00
|
|
|
"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
|
|
|
|
showStart "setkey" file
|
2011-01-26 04:17:38 +00:00
|
|
|
return $ Just $ perform file
|
|
|
|
|
|
|
|
perform :: FilePath -> CommandPerform
|
|
|
|
perform file = do
|
|
|
|
key <- cmdlineKey
|
2010-11-08 23:26:37 +00:00
|
|
|
-- the file might be on a different filesystem, so mv is used
|
2011-03-22 21:27:04 +00:00
|
|
|
-- rather than simply calling moveToObjectDir; disk space is also
|
|
|
|
-- checked this way.
|
2010-11-27 21:07:22 +00:00
|
|
|
ok <- getViaTmp key $ \dest -> do
|
|
|
|
if dest /= file
|
2011-02-25 05:13:01 +00:00
|
|
|
then liftIO $
|
2011-02-28 20:10:16 +00:00
|
|
|
boolSystem "mv" [File file, File dest]
|
2010-11-27 21:07:22 +00:00
|
|
|
else return True
|
2010-11-08 23:26:37 +00:00
|
|
|
if ok
|
2011-01-26 04:17:38 +00:00
|
|
|
then return $ Just $ cleanup
|
2010-11-08 23:26:37 +00:00
|
|
|
else error "mv failed!"
|
|
|
|
|
2011-01-26 04:17:38 +00:00
|
|
|
cleanup :: CommandCleanup
|
|
|
|
cleanup = do
|
|
|
|
key <- cmdlineKey
|
2010-11-02 23:04:24 +00:00
|
|
|
logStatus key ValuePresent
|
|
|
|
return True
|