2011-06-01 23:10:38 +00:00
|
|
|
{- git-annex UUID type
|
|
|
|
-
|
expire, trust et al, dead, describe: Support --json and --json-error-messages
For expire, the normal output is unchanged, but the --json output includes the uuid
in machine parseable form. Which could be very useful for this somewhat obscure
command. That needed ActionItemUUID to be implemented, which seemed like a lot
of work, but then ---
I had been going to skip implementing them for trust, untrust, dead, semitrust,
and describe, but putting the uuid in the json is useful information, it tells
what uuid git-annex picked given the input. It was not hard to support
these once ActionItemUUID was implemented.
Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
2023-05-05 19:29:49 +00:00
|
|
|
- Copyright 2011-2023 Joey Hess <id@joeyh.name>
|
2011-06-01 23:10:38 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-06-01 23:10:38 +00:00
|
|
|
-}
|
|
|
|
|
2019-01-01 19:39:45 +00:00
|
|
|
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, GeneralizedNewtypeDeriving #-}
|
2015-10-08 20:55:11 +00:00
|
|
|
|
2011-06-02 01:56:04 +00:00
|
|
|
module Types.UUID where
|
2011-06-01 23:10:38 +00:00
|
|
|
|
2019-01-01 17:49:19 +00:00
|
|
|
import qualified Data.ByteString as B
|
expire, trust et al, dead, describe: Support --json and --json-error-messages
For expire, the normal output is unchanged, but the --json output includes the uuid
in machine parseable form. Which could be very useful for this somewhat obscure
command. That needed ActionItemUUID to be implemented, which seemed like a lot
of work, but then ---
I had been going to skip implementing them for trust, untrust, dead, semitrust,
and describe, but putting the uuid in the json is useful information, it tells
what uuid git-annex picked given the input. It was not hard to support
these once ActionItemUUID was implemented.
Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
2023-05-05 19:29:49 +00:00
|
|
|
import qualified Data.Text as T
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
import qualified Data.Map as M
|
2014-04-16 00:13:35 +00:00
|
|
|
import qualified Data.UUID as U
|
|
|
|
import Data.Maybe
|
2019-01-01 19:39:45 +00:00
|
|
|
import Data.String
|
2019-01-09 18:00:35 +00:00
|
|
|
import Data.ByteString.Builder
|
2019-01-18 18:08:10 +00:00
|
|
|
import qualified Data.Semigroup as Sem
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
|
2019-12-05 18:36:43 +00:00
|
|
|
import Git.Types (ConfigValue(..))
|
2019-01-01 17:49:19 +00:00
|
|
|
import Utility.FileSystemEncoding
|
2019-02-21 16:22:50 +00:00
|
|
|
import Utility.QuickCheck
|
expire, trust et al, dead, describe: Support --json and --json-error-messages
For expire, the normal output is unchanged, but the --json output includes the uuid
in machine parseable form. Which could be very useful for this somewhat obscure
command. That needed ActionItemUUID to be implemented, which seemed like a lot
of work, but then ---
I had been going to skip implementing them for trust, untrust, dead, semitrust,
and describe, but putting the uuid in the json is useful information, it tells
what uuid git-annex picked given the input. It was not hard to support
these once ActionItemUUID was implemented.
Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
2023-05-05 19:29:49 +00:00
|
|
|
import Utility.Aeson
|
2016-11-17 21:19:04 +00:00
|
|
|
import qualified Utility.SimpleProtocol as Proto
|
|
|
|
|
2011-11-07 18:46:01 +00:00
|
|
|
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
|
2019-01-01 17:49:19 +00:00
|
|
|
data UUID = NoUUID | UUID B.ByteString
|
2012-08-08 20:06:01 +00:00
|
|
|
deriving (Eq, Ord, Show, Read)
|
2011-11-07 18:46:01 +00:00
|
|
|
|
2019-01-01 17:49:19 +00:00
|
|
|
class FromUUID a where
|
|
|
|
fromUUID :: UUID -> a
|
2011-11-07 18:46:01 +00:00
|
|
|
|
2015-10-08 20:55:11 +00:00
|
|
|
class ToUUID a where
|
|
|
|
toUUID :: a -> UUID
|
|
|
|
|
2019-01-01 17:49:19 +00:00
|
|
|
instance FromUUID UUID where
|
|
|
|
fromUUID = id
|
|
|
|
|
2015-10-08 21:58:32 +00:00
|
|
|
instance ToUUID UUID where
|
|
|
|
toUUID = id
|
|
|
|
|
2019-01-01 17:49:19 +00:00
|
|
|
instance FromUUID B.ByteString where
|
|
|
|
fromUUID (UUID u) = u
|
|
|
|
fromUUID NoUUID = B.empty
|
|
|
|
|
|
|
|
instance ToUUID B.ByteString where
|
|
|
|
toUUID b
|
|
|
|
| B.null b = NoUUID
|
|
|
|
| otherwise = UUID b
|
|
|
|
|
|
|
|
instance FromUUID String where
|
2021-08-11 00:45:02 +00:00
|
|
|
fromUUID s = decodeBS (fromUUID s)
|
2019-01-01 17:49:19 +00:00
|
|
|
|
2015-10-08 20:55:11 +00:00
|
|
|
instance ToUUID String where
|
2021-08-11 00:45:02 +00:00
|
|
|
toUUID s = toUUID (encodeBS s)
|
2019-01-01 17:49:19 +00:00
|
|
|
|
2019-12-05 18:36:43 +00:00
|
|
|
instance FromUUID ConfigValue where
|
|
|
|
fromUUID s = (ConfigValue (fromUUID s))
|
|
|
|
|
|
|
|
instance ToUUID ConfigValue where
|
|
|
|
toUUID (ConfigValue v) = toUUID v
|
2020-04-13 17:35:22 +00:00
|
|
|
toUUID NoConfigValue = NoUUID
|
2019-12-05 18:36:43 +00:00
|
|
|
|
2019-01-01 17:49:19 +00:00
|
|
|
-- There is no matching FromUUID U.UUID because a git-annex UUID may
|
|
|
|
-- be NoUUID or perhaps contain something not allowed in a canonical UUID.
|
|
|
|
instance ToUUID U.UUID where
|
|
|
|
toUUID = toUUID . U.toASCIIBytes
|
add ConfigMonitor thread
Monitors git-annex branch for changes, which are noticed by the Merger
thread whenever the branch ref is changed (either due to an incoming push,
or a local change), and refreshes cached config values for modified config
files.
Rate limited to run no more often than once per minute. This is important
because frequent git-annex branch changes happen when files are being
added, or transferred, etc.
A primary use case is that, when preferred content changes are made,
and get pushed to remotes, the remotes start honoring those settings.
Other use cases include propigating repository description and trust
changes to remotes, and learning when a remote has added a new special
remote, so the webapp can present the GUI to enable that special remote
locally.
Also added a uuid.log cache. All other config files already had caches.
2012-10-20 20:37:06 +00:00
|
|
|
|
expire, trust et al, dead, describe: Support --json and --json-error-messages
For expire, the normal output is unchanged, but the --json output includes the uuid
in machine parseable form. Which could be very useful for this somewhat obscure
command. That needed ActionItemUUID to be implemented, which seemed like a lot
of work, but then ---
I had been going to skip implementing them for trust, untrust, dead, semitrust,
and describe, but putting the uuid in the json is useful information, it tells
what uuid git-annex picked given the input. It was not hard to support
these once ActionItemUUID was implemented.
Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
2023-05-05 19:29:49 +00:00
|
|
|
instance ToJSON' UUID where
|
|
|
|
toJSON' (UUID u) = toJSON' u
|
|
|
|
toJSON' NoUUID = toJSON' ""
|
|
|
|
|
|
|
|
instance FromJSON UUID where
|
|
|
|
parseJSON (String t)
|
|
|
|
| isUUID s = pure (toUUID s)
|
|
|
|
| otherwise = mempty
|
|
|
|
where
|
|
|
|
s = T.unpack t
|
|
|
|
parseJSON _ = mempty
|
|
|
|
|
2019-01-09 18:00:35 +00:00
|
|
|
buildUUID :: UUID -> Builder
|
|
|
|
buildUUID (UUID b) = byteString b
|
2019-01-10 21:17:37 +00:00
|
|
|
buildUUID NoUUID = mempty
|
2019-01-09 18:00:35 +00:00
|
|
|
|
2014-04-16 00:13:35 +00:00
|
|
|
isUUID :: String -> Bool
|
|
|
|
isUUID = isJust . U.fromString
|
|
|
|
|
2019-01-01 19:39:45 +00:00
|
|
|
-- A description of a UUID.
|
|
|
|
newtype UUIDDesc = UUIDDesc B.ByteString
|
2019-01-18 18:08:10 +00:00
|
|
|
deriving (Eq, Sem.Semigroup, Monoid, IsString)
|
2019-01-01 19:39:45 +00:00
|
|
|
|
|
|
|
fromUUIDDesc :: UUIDDesc -> String
|
|
|
|
fromUUIDDesc (UUIDDesc d) = decodeBS d
|
|
|
|
|
|
|
|
toUUIDDesc :: String -> UUIDDesc
|
|
|
|
toUUIDDesc = UUIDDesc . encodeBS
|
|
|
|
|
|
|
|
type UUIDDescMap = M.Map UUID UUIDDesc
|
2016-11-17 21:19:04 +00:00
|
|
|
|
|
|
|
instance Proto.Serializable UUID where
|
|
|
|
serialize = fromUUID
|
|
|
|
deserialize = Just . toUUID
|
2019-02-21 16:22:50 +00:00
|
|
|
|
|
|
|
instance Arbitrary UUID where
|
|
|
|
arbitrary = frequency [(1, return NoUUID), (3, UUID <$> arb)]
|
|
|
|
where
|
2019-03-06 20:44:17 +00:00
|
|
|
arb = encodeBS <$> listOf1 (elements uuidchars)
|
|
|
|
uuidchars = '-' : ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']
|