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