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.
This commit is contained in:
parent
3742263c99
commit
c873586e14
6 changed files with 10 additions and 25 deletions
|
@ -41,6 +41,7 @@ import Config
|
||||||
import qualified Data.UUID as U
|
import qualified Data.UUID as U
|
||||||
import qualified Data.UUID.V4 as U4
|
import qualified Data.UUID.V4 as U4
|
||||||
import qualified Data.UUID.V5 as U5
|
import qualified Data.UUID.V5 as U5
|
||||||
|
import qualified Data.ByteString as S
|
||||||
import Data.String
|
import Data.String
|
||||||
|
|
||||||
configkeyUUID :: ConfigKey
|
configkeyUUID :: ConfigKey
|
||||||
|
@ -53,13 +54,13 @@ genUUID = toUUID <$> U4.nextRandom
|
||||||
{- Generates a UUID from a given string, using a namespace.
|
{- Generates a UUID from a given string, using a namespace.
|
||||||
- Given the same namespace, the same string will always result
|
- Given the same namespace, the same string will always result
|
||||||
- in the same UUID. -}
|
- in the same UUID. -}
|
||||||
genUUIDInNameSpace :: U.UUID -> String -> UUID
|
genUUIDInNameSpace :: U.UUID -> S.ByteString -> UUID
|
||||||
genUUIDInNameSpace namespace = toUUID . U5.generateNamed namespace . s2w8
|
genUUIDInNameSpace namespace = toUUID . U5.generateNamed namespace . S.unpack
|
||||||
|
|
||||||
{- Namespace used for UUIDs derived from git-remote-gcrypt ids. -}
|
{- Namespace used for UUIDs derived from git-remote-gcrypt ids. -}
|
||||||
gCryptNameSpace :: U.UUID
|
gCryptNameSpace :: U.UUID
|
||||||
gCryptNameSpace = U5.generateNamed U5.namespaceURL $
|
gCryptNameSpace = U5.generateNamed U5.namespaceURL $
|
||||||
s2w8 "http://git-annex.branchable.com/design/gcrypt/"
|
S.unpack "http://git-annex.branchable.com/design/gcrypt/"
|
||||||
|
|
||||||
{- Get current repository's UUID. -}
|
{- Get current repository's UUID. -}
|
||||||
getUUID :: Annex UUID
|
getUUID :: Annex UUID
|
||||||
|
|
|
@ -319,7 +319,7 @@ testServer sshinput@(SshInput { inputHostname = Just hn }) = do
|
||||||
finduuid (k, v)
|
finduuid (k, v)
|
||||||
| k == "annex.uuid" = Just $ toUUID v
|
| k == "annex.uuid" = Just $ toUUID v
|
||||||
| k == fromConfigKey GCrypt.coreGCryptId =
|
| k == fromConfigKey GCrypt.coreGCryptId =
|
||||||
Just $ genUUIDInNameSpace gCryptNameSpace v
|
Just $ genUUIDInNameSpace gCryptNameSpace (encodeBS v)
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
checkcommand c = "if which " ++ c ++ "; then " ++ report c ++ "; fi"
|
checkcommand c = "if which " ++ c ++ "; then " ++ report c ++ "; fi"
|
||||||
|
|
|
@ -29,7 +29,7 @@ start gcryptid = starting "gcryptsetup" (ActionItemOther Nothing) (SeekInput [gc
|
||||||
|
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
gu <- Remote.GCrypt.getGCryptUUID True g
|
gu <- Remote.GCrypt.getGCryptUUID True g
|
||||||
let newgu = genUUIDInNameSpace gCryptNameSpace gcryptid
|
let newgu = genUUIDInNameSpace gCryptNameSpace (encodeBS gcryptid)
|
||||||
if isNothing gu || gu == Just newgu
|
if isNothing gu || gu == Just newgu
|
||||||
then if Git.repoIsLocalBare g
|
then if Git.repoIsLocalBare g
|
||||||
then do
|
then do
|
||||||
|
|
|
@ -112,7 +112,7 @@ gen baser u rc gc rs = do
|
||||||
-- that is now available. Also need to set the gcrypt particiants
|
-- that is now available. Also need to set the gcrypt particiants
|
||||||
-- correctly.
|
-- correctly.
|
||||||
resetup gcryptid r = do
|
resetup gcryptid r = do
|
||||||
let u' = genUUIDInNameSpace gCryptNameSpace gcryptid
|
let u' = genUUIDInNameSpace gCryptNameSpace (encodeBS gcryptid)
|
||||||
v <- M.lookup u' <$> remoteConfigMap
|
v <- M.lookup u' <$> remoteConfigMap
|
||||||
case (Git.remoteName baser, v) of
|
case (Git.remoteName baser, v) of
|
||||||
(Just remotename, Just rc') -> do
|
(Just remotename, Just rc') -> do
|
||||||
|
@ -263,7 +263,7 @@ gCryptSetup _ mu _ c gc = go $ fromProposedAccepted <$> M.lookup gitRepoField c
|
||||||
case Git.GCrypt.remoteRepoId g (Just remotename) of
|
case Git.GCrypt.remoteRepoId g (Just remotename) of
|
||||||
Nothing -> giveup "unable to determine gcrypt-id of remote"
|
Nothing -> giveup "unable to determine gcrypt-id of remote"
|
||||||
Just gcryptid -> do
|
Just gcryptid -> do
|
||||||
let u = genUUIDInNameSpace gCryptNameSpace gcryptid
|
let u = genUUIDInNameSpace gCryptNameSpace (encodeBS gcryptid)
|
||||||
if Just u == mu || isNothing mu
|
if Just u == mu || isNothing mu
|
||||||
then do
|
then do
|
||||||
method <- setupRepo gcryptid =<< inRepo (Git.Construct.fromRemoteLocation gitrepo False)
|
method <- setupRepo gcryptid =<< inRepo (Git.Construct.fromRemoteLocation gitrepo False)
|
||||||
|
@ -489,7 +489,7 @@ toAccessMethod _ = AccessRsyncOverSsh
|
||||||
getGCryptUUID :: Bool -> Git.Repo -> Annex (Maybe UUID)
|
getGCryptUUID :: Bool -> Git.Repo -> Annex (Maybe UUID)
|
||||||
getGCryptUUID fast r = do
|
getGCryptUUID fast r = do
|
||||||
dummycfg <- liftIO dummyRemoteGitConfig
|
dummycfg <- liftIO dummyRemoteGitConfig
|
||||||
(genUUIDInNameSpace gCryptNameSpace <$>) . fst
|
(genUUIDInNameSpace gCryptNameSpace . encodeBS <$>) . fst
|
||||||
<$> getGCryptId fast r dummycfg
|
<$> getGCryptId fast r dummycfg
|
||||||
|
|
||||||
coreGCryptId :: ConfigKey
|
coreGCryptId :: ConfigKey
|
||||||
|
|
|
@ -327,7 +327,7 @@ tryGitConfigRead autoinit r hasuuid
|
||||||
case Git.GCrypt.remoteRepoId g (Git.remoteName r) of
|
case Git.GCrypt.remoteRepoId g (Git.remoteName r) of
|
||||||
Nothing -> return r
|
Nothing -> return r
|
||||||
Just v -> storeUpdatedRemote $ liftIO $ setUUID r $
|
Just v -> storeUpdatedRemote $ liftIO $ setUUID r $
|
||||||
genUUIDInNameSpace gCryptNameSpace v
|
genUUIDInNameSpace gCryptNameSpace (encodeBS v)
|
||||||
|
|
||||||
{- The local repo may not yet be initialized, so try to initialize
|
{- The local repo may not yet be initialized, so try to initialize
|
||||||
- it if allowed. However, if that fails, still return the read
|
- it if allowed. However, if that fails, still return the read
|
||||||
|
|
|
@ -10,12 +10,8 @@
|
||||||
module Utility.Data (
|
module Utility.Data (
|
||||||
firstJust,
|
firstJust,
|
||||||
eitherToMaybe,
|
eitherToMaybe,
|
||||||
s2w8,
|
|
||||||
w82s,
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Word
|
|
||||||
|
|
||||||
{- First item in the list that is not Nothing. -}
|
{- First item in the list that is not Nothing. -}
|
||||||
firstJust :: Eq a => [Maybe a] -> Maybe a
|
firstJust :: Eq a => [Maybe a] -> Maybe a
|
||||||
firstJust ms = case dropWhile (== Nothing) ms of
|
firstJust ms = case dropWhile (== Nothing) ms of
|
||||||
|
@ -24,15 +20,3 @@ firstJust ms = case dropWhile (== Nothing) ms of
|
||||||
|
|
||||||
eitherToMaybe :: Either a b -> Maybe b
|
eitherToMaybe :: Either a b -> Maybe b
|
||||||
eitherToMaybe = either (const Nothing) Just
|
eitherToMaybe = either (const Nothing) Just
|
||||||
|
|
||||||
c2w8 :: Char -> Word8
|
|
||||||
c2w8 = fromIntegral . fromEnum
|
|
||||||
|
|
||||||
w82c :: Word8 -> Char
|
|
||||||
w82c = toEnum . fromIntegral
|
|
||||||
|
|
||||||
s2w8 :: String -> [Word8]
|
|
||||||
s2w8 = map c2w8
|
|
||||||
|
|
||||||
w82s :: [Word8] -> String
|
|
||||||
w82s = map w82c
|
|
||||||
|
|
Loading…
Reference in a new issue