blob: 6f6078e4ba717162b0d6572d54b47af30f7b4c77 (
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
45
46
47
48
49
50
|
{- 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
import Messages
command :: [Command]
command = [repoCommand "setkey" (paramRepeating paramKey) seek
"sets annexed content for a key using a temp file"]
seek :: [CommandSeek]
seek = [withTempFile start]
{- Sets cached content for a key. -}
start :: CommandStartString
start file = do
showStart "setkey" file
return $ Just $ 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
then return $ Just $ cleanup
else error "mv failed!"
cleanup :: CommandCleanup
cleanup = do
key <- cmdlineKey
logStatus key ValuePresent
return True
|