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