git-annex/Command/GCryptSetup.hs
Joey Hess c873586e14
eliminate s2w8 and w82s
Note that the use of s2w8 in genUUIDInNameSpace made it truncate unicode
characters. Luckily, genUUIDInNameSpace is only ever used on ASCII
strings as far as I can determine. In particular, git-remote-gcrypt's
gcrypt-id is an ASCII string.
2023-10-26 13:12:57 -04:00

39 lines
1.1 KiB
Haskell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{- git-annex command
-
- Copyright 2013 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Command.GCryptSetup where
import Command
import Annex.UUID
import qualified Remote.GCrypt
import qualified Git
cmd :: Command
cmd = dontCheck repoExists $ noCommit $
command "gcryptsetup" SectionPlumbing
"sets up gcrypt repository"
paramValue (withParams seek)
seek :: CmdParams -> CommandSeek
seek = withStrings (commandAction . start)
start :: String -> CommandStart
start gcryptid = starting "gcryptsetup" (ActionItemOther Nothing) (SeekInput [gcryptid]) $ do
u <- getUUID
when (u /= NoUUID) $
giveup "gcryptsetup refusing to run; this repository already has a git-annex uuid!"
g <- gitRepo
gu <- Remote.GCrypt.getGCryptUUID True g
let newgu = genUUIDInNameSpace gCryptNameSpace (encodeBS gcryptid)
if isNothing gu || gu == Just newgu
then if Git.repoIsLocalBare g
then do
void $ Remote.GCrypt.setupRepo gcryptid g
next $ return True
else giveup "cannot use gcrypt in a non-bare repository"
else giveup "gcryptsetup uuid mismatch"