aboutsummaryrefslogtreecommitdiff
path: root/Command/SetKey.hs
blob: 50e9a590b124f8f53a7b1e171c44fb06c7440d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{- 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 Control.Monad (when)

import Command
import qualified Annex
import Utility
import qualified Backend
import LocationLog
import Types
import Core
import Messages

{- Sets cached content for a key. -}
start :: SubCmdStartString
start file = do
	keyname <- Annex.flagGet "key"
	when (null keyname) $ error "please specify the key with --key"
	backends <- Backend.list
	let key = genKey (backends !! 0) keyname
	showStart "setkey" file
	return $ Just $ perform file key
perform :: FilePath -> Key -> SubCmdPerform
perform file key = do
	-- the file might be on a different filesystem, so mv is used
	-- rather than simply calling moveToObjectDir key file
	ok <- getViaTmp key $ \dest -> liftIO $ boolSystem "mv" [file, dest]
	if ok
		then return $ Just $ cleanup key
		else error "mv failed!"

cleanup :: Key -> SubCmdCleanup
cleanup key = do
	logStatus key ValuePresent
	return True