add git-annex updatecluster command

Seems to work fine, making the right changes to the git-annex branch.
This commit is contained in:
Joey Hess 2024-06-14 14:21:50 -04:00
parent 2844230dfe
commit bbf261487d
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 114 additions and 28 deletions

View file

@ -10,6 +10,7 @@
module Types.Cluster (
ClusterUUID,
mkClusterUUID,
genClusterUUID,
isClusterUUID,
fromClusterUUID,
ClusterNodeUUID(..),
@ -32,17 +33,13 @@ import Data.Char
newtype ClusterUUID = ClusterUUID UUID
deriving (Show, Eq, Ord)
-- Smart constructor for a ClusterUUID.
--
-- The input UUID can be any regular UUID (eg V4). It is converted to a valid
-- cluster UUID.
-- Smart constructor for a ClusterUUID. Only allows valid cluster UUIDs.
mkClusterUUID :: UUID -> Maybe ClusterUUID
mkClusterUUID (UUID b)
| B.length b > 14 = Just $ ClusterUUID $ UUID $
"ac" <> B.drop 2 (B.take 14 b) <> "8" <> B.drop 15 b
mkClusterUUID u
| isClusterUUID u = Just (ClusterUUID u)
| otherwise = Nothing
mkClusterUUID NoUUID = Nothing
-- Check if it is a valid cluster UUID.
isClusterUUID :: UUID -> Bool
isClusterUUID (UUID b)
| B.take 2 b == "ac" =
@ -55,6 +52,15 @@ isClusterUUID (UUID b)
eight = fromIntegral (ord '8')
isClusterUUID _ = False
-- Generates a ClusterUUID from any regular UUID (eg V4).
-- It is converted to a valid cluster UUID.
genClusterUUID :: UUID -> Maybe ClusterUUID
genClusterUUID (UUID b)
| B.length b > 14 = Just $ ClusterUUID $ UUID $
"ac" <> B.drop 2 (B.take 14 b) <> "8" <> B.drop 15 b
| otherwise = Nothing
genClusterUUID NoUUID = Nothing
fromClusterUUID :: ClusterUUID -> UUID
fromClusterUUID (ClusterUUID u) = u
@ -69,3 +75,4 @@ data Clusters = Clusters
{ clusterUUIDs :: M.Map ClusterUUID (S.Set ClusterNodeUUID)
, clusterNodeUUIDs :: M.Map ClusterNodeUUID (S.Set ClusterUUID)
}
deriving (Show)