aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 14:47:46 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 14:47:46 -0400
commit64dfd213e46f983d5cb504b446597e87f71440de (patch)
treeee70642df0e95c99828920b8d071d057b9ee5acf
parentbab88f3596c570346a3d069af9e3c8ed92e473c9 (diff)
git-annex-shell: Added lockcontent command, to prevent dropping of key's content.
-rw-r--r--CmdLine/GitAnnexShell.hs2
-rw-r--r--Command/LockContent.hs45
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex-shell.mdwn11
4 files changed, 60 insertions, 0 deletions
diff --git a/CmdLine/GitAnnexShell.hs b/CmdLine/GitAnnexShell.hs
index 59c861582..f9678d144 100644
--- a/CmdLine/GitAnnexShell.hs
+++ b/CmdLine/GitAnnexShell.hs
@@ -20,6 +20,7 @@ import Remote.GCrypt (getGCryptUUID)
import qualified Command.ConfigList
import qualified Command.InAnnex
+import qualified Command.LockContent
import qualified Command.DropKey
import qualified Command.RecvKey
import qualified Command.SendKey
@@ -32,6 +33,7 @@ cmds_readonly :: [Command]
cmds_readonly =
[ Command.ConfigList.cmd
, gitAnnexShellCheck Command.InAnnex.cmd
+ , gitAnnexShellCheck Command.LockContent.cmd
, gitAnnexShellCheck Command.SendKey.cmd
, gitAnnexShellCheck Command.TransferInfo.cmd
, gitAnnexShellCheck Command.NotifyChanges.cmd
diff --git a/Command/LockContent.hs b/Command/LockContent.hs
new file mode 100644
index 000000000..bab5c9276
--- /dev/null
+++ b/Command/LockContent.hs
@@ -0,0 +1,45 @@
+{- 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 Common.Annex
+import Command
+import Annex.Content
+import Types.Key
+
+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
+-- present, and print out a "1". Wait for the caller to send a line before
+-- dropping the lock.
+start :: [String] -> CommandStart
+start [ks] = do
+ ok <- lockContentShared k locksuccess
+ `catchNonAsync` (const $ return False)
+ liftIO $ if ok
+ then exitSuccess
+ else exitFailure
+ where
+ k = fromMaybe (error "bad key") (file2key ks)
+ locksuccess = ifM (inAnnex k)
+ ( liftIO $ do
+ putStrLn "OK"
+ hFlush stdout
+ _ <- getLine
+ return True
+ , return False
+ )
+start _ = error "Specify exactly 1 key."
diff --git a/debian/changelog b/debian/changelog
index ddeb94338..f3ffa5975 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -20,6 +20,8 @@ git-annex (5.20150931) UNRELEASED; urgency=medium
and stop recommending bittornado | bittorrent.
* Debian: Remove dependency on transformers library, as it is now
included in ghc.
+ * git-annex-shell: Added lockcontent command, to prevent dropping of
+ key's content.
-- Joey Hess <id@joeyh.name> Thu, 01 Oct 2015 12:42:56 -0400
diff --git a/doc/git-annex-shell.mdwn b/doc/git-annex-shell.mdwn
index d0e0930c5..73517ba89 100644
--- a/doc/git-annex-shell.mdwn
+++ b/doc/git-annex-shell.mdwn
@@ -43,6 +43,17 @@ first "/~/" or "/~user/" is expanded to the specified home directory.
Exits 100 if it's unable to tell (perhaps the key is in the process of
being removed from the annex).
+* lockcontent directory key
+
+ This locks a key's content in place in the annex, preventing it from
+ being dropped.
+
+ Once the content is successfully locked, outputs "OK". Then the content
+ remains locked until a newline is received from the caller or the
+ connection is broken.
+
+ Exits nonzero if the content is not present, or could not be locked.
+
* dropkey directory [key ...]
This drops the annexed data for the specified keys.