2015-10-08 18:47:46 +00:00
|
|
|
{- git-annex-shell command
|
|
|
|
-
|
|
|
|
- Copyright 2015 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.LockContent where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.Content
|
2015-10-09 20:55:41 +00:00
|
|
|
import Remote.Helper.Ssh (contentLockedMarker)
|
2016-12-09 17:34:00 +00:00
|
|
|
import Utility.SimpleProtocol
|
2015-10-08 18:47:46 +00:00
|
|
|
|
|
|
|
cmd :: Command
|
|
|
|
cmd = noCommit $
|
|
|
|
command "lockcontent" SectionPlumbing
|
|
|
|
"locks key's content in the annex, preventing it being dropped"
|
|
|
|
paramKey
|
|
|
|
(withParams seek)
|
|
|
|
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
|
|
seek = withWords start
|
|
|
|
|
|
|
|
-- First, lock the content. Then, make sure the content is actually
|
2016-04-13 17:04:38 +00:00
|
|
|
-- present, and print out "OK". Wait for the caller to send a line before
|
2015-10-08 18:47:46 +00:00
|
|
|
-- dropping the lock.
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start [ks] = do
|
2015-10-08 20:55:11 +00:00
|
|
|
ok <- lockContentShared k (const locksuccess)
|
2015-10-08 18:47:46 +00:00
|
|
|
`catchNonAsync` (const $ return False)
|
|
|
|
liftIO $ if ok
|
|
|
|
then exitSuccess
|
|
|
|
else exitFailure
|
|
|
|
where
|
2016-11-16 01:29:54 +00:00
|
|
|
k = fromMaybe (giveup "bad key") (file2key ks)
|
2015-10-08 18:47:46 +00:00
|
|
|
locksuccess = ifM (inAnnex k)
|
|
|
|
( liftIO $ do
|
2015-10-09 20:55:41 +00:00
|
|
|
putStrLn contentLockedMarker
|
2015-10-08 18:47:46 +00:00
|
|
|
hFlush stdout
|
2016-12-09 17:34:00 +00:00
|
|
|
_ <- getProtocolLine stdin
|
2015-10-08 18:47:46 +00:00
|
|
|
return True
|
|
|
|
, return False
|
|
|
|
)
|
2016-11-16 01:29:54 +00:00
|
|
|
start _ = giveup "Specify exactly 1 key."
|