summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CmdLine/GitAnnex.hs2
-rw-r--r--Command/SetKey.hs49
-rw-r--r--debian/changelog3
-rw-r--r--doc/git-annex-dropkey.mdwn2
-rw-r--r--doc/git-annex-setkey.mdwn30
-rw-r--r--doc/git-annex.mdwn7
6 files changed, 93 insertions, 0 deletions
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index 326dd3b2b..354f451e7 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -26,6 +26,7 @@ import qualified Command.ContentLocation
import qualified Command.ExamineKey
import qualified Command.FromKey
import qualified Command.RegisterUrl
+import qualified Command.SetKey
import qualified Command.DropKey
import qualified Command.TransferKey
import qualified Command.TransferKeys
@@ -159,6 +160,7 @@ cmds = concat
, Command.ExamineKey.cmd
, Command.FromKey.cmd
, Command.RegisterUrl.cmd
+ , Command.SetKey.cmd
, Command.DropKey.cmd
, Command.TransferKey.cmd
, Command.TransferKeys.cmd
diff --git a/Command/SetKey.hs b/Command/SetKey.hs
new file mode 100644
index 000000000..02118fb14
--- /dev/null
+++ b/Command/SetKey.hs
@@ -0,0 +1,49 @@
+{- git-annex command
+ -
+ - Copyright 2010, 2015 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.SetKey where
+
+import Common.Annex
+import Command
+import Logs.Location
+import Annex.Content
+import Types.Key
+
+cmd :: [Command]
+cmd = [command "setkey" (paramPair paramKey paramPath) seek
+ SectionPlumbing "sets annexed content for a key"]
+
+seek :: CommandSeek
+seek = withWords start
+
+start :: [String] -> CommandStart
+start (keyname:file:[]) = do
+ showStart "setkey" file
+ next $ perform file (mkKey keyname)
+start _ = error "specify a key and a content file"
+
+mkKey :: String -> Key
+mkKey = fromMaybe (error "bad key") . file2key
+
+perform :: FilePath -> Key -> CommandPerform
+perform file key = do
+ -- the file might be on a different filesystem, so mv is used
+ -- rather than simply calling moveAnnex; disk space is also
+ -- checked this way.
+ ok <- getViaTmp key $ \dest ->
+ if dest /= file
+ then liftIO $
+ boolSystem "mv" [File file, File dest]
+ else return True
+ if ok
+ then next $ cleanup key
+ else error "mv failed!"
+
+cleanup :: Key -> CommandCleanup
+cleanup key = do
+ logStatus key InfoPresent
+ return True
diff --git a/debian/changelog b/debian/changelog
index 608a84d3b..795921a9e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,9 @@ git-annex (5.20150618) UNRELEASED; urgency=medium
* assistant: Fix ANNEX_SHELL_DIR written to ~/.ssh/authorized_keys
in local pairing to be the absolute path to the repository, not "."
This was a reversion caused by the relative path changes in 5.20150113.
+ * Brought back the setkey plumbing command that was removed in 2011, since
+ we found a use case for it. Note that the command's syntax was changed
+ for consistency.
-- Joey Hess <id@joeyh.name> Thu, 02 Jul 2015 12:31:14 -0400
diff --git a/doc/git-annex-dropkey.mdwn b/doc/git-annex-dropkey.mdwn
index 7a25e23b2..0db29f900 100644
--- a/doc/git-annex-dropkey.mdwn
+++ b/doc/git-annex-dropkey.mdwn
@@ -21,6 +21,8 @@ exist; using it can easily result in data loss.
[[git-annex]](1)
+[[git-annex-setkey]](1)
+
# AUTHOR
Joey Hess <id@joeyh.name>
diff --git a/doc/git-annex-setkey.mdwn b/doc/git-annex-setkey.mdwn
new file mode 100644
index 000000000..439984c2b
--- /dev/null
+++ b/doc/git-annex-setkey.mdwn
@@ -0,0 +1,30 @@
+# NAME
+
+git-annex setkey - sets annexed content for a key
+
+# SYNOPSIS
+
+git annex setkey key file
+
+# DESCRIPTION
+
+This plumbing-level command makes the content of the specified key
+be set to the specified file. The file is moved into the annex.
+
+No checking is done that the file contains the expected contents of the key.
+So it's generally a better idea to use [[git-annex-reinject]](1) instead of
+this command.
+
+# SEE ALSO
+
+[[git-annex]](1)
+
+[[git-annex-reinject]](1)
+
+[[git-annex-dropkey]](1)
+
+# AUTHOR
+
+Joey Hess <id@joeyh.name>
+
+Warning: Automatically converted into a man page by mdwn2man. Edit with care.
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index a0d5a0b00..7a3edf0ef 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -547,6 +547,13 @@ subdirectories).
See [[git-annex-registerurl]](1) for details.
+* `setkey key file`
+
+ Moves a file into the annex as the content of a key.
+
+ See [[git-annex-setkey]](1) for details.
+
+
* `dropkey [key ...]`
Drops annexed content for specified keys.