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.

This commit is contained in:
Joey Hess 2015-07-02 17:44:25 -04:00
parent ecedab0120
commit 1529add61a
6 changed files with 93 additions and 0 deletions

View file

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

49
Command/SetKey.hs Normal file
View file

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

3
debian/changelog vendored
View file

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

View file

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

30
doc/git-annex-setkey.mdwn Normal file
View file

@ -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.

View file

@ -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.