git-annex/Command/SetKey.hs
Joey Hess aa2d8e33df free space checking
Free space checking is now done, for transfers of data for keys that have free space metadata.
(Notably, not for SHA* keys generated with git-annex 0.24 or earlier.)

The code is believed to work on Linux, FreeBSD, and OSX; check compile-time
messages to see if it is not enabled for your OS.
2011-03-22 17:27:04 -04:00

50 lines
1.1 KiB
Haskell

{- 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