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
|
2011-08-22 20:14:12 +00:00
|
|
|
import Utility.SafeCommand
|
2010-11-02 23:04:24 +00:00
|
|
|
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-07-15 16:47:14 +00:00
|
|
|
command = [repoCommand "setkey" paramPath 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]
|
2011-08-17 00:47:48 +00:00
|
|
|
seek = [withStrings start]
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- Sets cached content for a key. -}
|
2011-09-15 20:50:49 +00:00
|
|
|
start :: FilePath -> CommandStart
|
2010-11-08 23:26:37 +00:00
|
|
|
start file = do
|
|
|
|
showStart "setkey" 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-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.
|
2011-07-15 16:47:14 +00:00
|
|
|
ok <- getViaTmp key $ \dest ->
|
2010-11-27 21:07:22 +00:00
|
|
|
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-05-15 06:02:46 +00:00
|
|
|
then next 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
|
2011-07-01 19:24:07 +00:00
|
|
|
logStatus key InfoPresent
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|