git-annex/Command/SetKey.hs

51 lines
1.1 KiB
Haskell
Raw Normal View History

{- 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
import Content
2010-11-08 19:15:21 +00:00
import Messages
command :: [Command]
command = [repoCommand "setkey" (paramRepeating paramKey) seek
"sets annexed content for a key using a temp file"]
seek :: [CommandSeek]
2010-11-11 22:54:52 +00:00
seek = [withTempFile start]
{- Sets cached content for a key. -}
start :: CommandStartString
start file = do
showStart "setkey" file
2011-05-15 06:02:46 +00:00
next $ perform file
perform :: FilePath -> CommandPerform
perform file = do
key <- cmdlineKey
-- the file might be on a different filesystem, so mv is used
-- rather than simply calling moveToObjectDir; disk space is also
-- checked this way.
ok <- getViaTmp key $ \dest -> do
if dest /= file
then liftIO $
boolSystem "mv" [File file, File dest]
else return True
if ok
2011-05-15 06:02:46 +00:00
then next cleanup
else error "mv failed!"
cleanup :: CommandCleanup
cleanup = do
key <- cmdlineKey
logStatus key ValuePresent
return True