2015-04-30 18:02:56 +00:00
|
|
|
{- git-annex numcopies configuration and checking
|
2014-01-21 22:08:56 +00:00
|
|
|
-
|
2024-06-16 15:34:35 +00:00
|
|
|
- Copyright 2014-2024 Joey Hess <id@joeyh.name>
|
2014-01-21 22:08:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-01-21 22:08:56 +00:00
|
|
|
-}
|
|
|
|
|
2023-04-10 21:03:41 +00:00
|
|
|
{-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable, OverloadedStrings #-}
|
2015-10-09 17:07:03 +00:00
|
|
|
|
2015-04-30 18:02:56 +00:00
|
|
|
module Annex.NumCopies (
|
2014-01-21 22:08:56 +00:00
|
|
|
module Types.NumCopies,
|
|
|
|
module Logs.NumCopies,
|
2021-01-06 18:11:08 +00:00
|
|
|
getFileNumMinCopies,
|
2021-06-15 15:12:27 +00:00
|
|
|
getSafestNumMinCopies,
|
|
|
|
getSafestNumMinCopies',
|
2014-01-21 22:08:56 +00:00
|
|
|
getGlobalFileNumCopies,
|
|
|
|
getNumCopies,
|
2021-01-06 18:11:08 +00:00
|
|
|
getMinCopies,
|
2014-01-21 22:08:56 +00:00
|
|
|
deprecatedNumCopies,
|
2015-04-12 16:49:11 +00:00
|
|
|
defaultNumCopies,
|
|
|
|
numCopiesCheck,
|
|
|
|
numCopiesCheck',
|
2024-06-16 19:07:48 +00:00
|
|
|
numCopiesCheck'',
|
2024-06-16 15:34:35 +00:00
|
|
|
numCopiesCount,
|
2015-10-09 15:09:46 +00:00
|
|
|
verifyEnoughCopiesToDrop,
|
2015-10-09 18:57:32 +00:00
|
|
|
verifiableCopies,
|
2015-10-09 20:16:03 +00:00
|
|
|
UnVerifiedCopy(..),
|
2014-01-21 22:08:56 +00:00
|
|
|
) where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-01-21 22:08:56 +00:00
|
|
|
import qualified Annex
|
|
|
|
import Types.NumCopies
|
|
|
|
import Logs.NumCopies
|
|
|
|
import Logs.Trust
|
2024-06-23 10:20:11 +00:00
|
|
|
import Logs.Cluster
|
2014-01-21 22:08:56 +00:00
|
|
|
import Annex.CheckAttr
|
|
|
|
import qualified Remote
|
2015-10-09 16:36:04 +00:00
|
|
|
import qualified Types.Remote as Remote
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.Content
|
2015-10-09 18:57:32 +00:00
|
|
|
import Annex.UUID
|
2021-06-15 15:12:27 +00:00
|
|
|
import Annex.CatFile
|
|
|
|
import qualified Database.Keys
|
2014-01-21 22:08:56 +00:00
|
|
|
|
2015-10-09 17:07:03 +00:00
|
|
|
import Control.Exception
|
2024-06-23 10:20:11 +00:00
|
|
|
import qualified Control.Monad.Catch as MC
|
2015-10-09 17:07:03 +00:00
|
|
|
import Data.Typeable
|
2024-06-23 10:20:11 +00:00
|
|
|
import qualified Data.Set as S
|
|
|
|
import qualified Data.Map as M
|
2015-10-09 17:07:03 +00:00
|
|
|
|
2014-01-21 22:08:56 +00:00
|
|
|
defaultNumCopies :: NumCopies
|
2022-03-28 19:19:52 +00:00
|
|
|
defaultNumCopies = configuredNumCopies 1
|
2014-01-21 22:08:56 +00:00
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
defaultMinCopies :: MinCopies
|
2022-03-28 19:19:52 +00:00
|
|
|
defaultMinCopies = configuredMinCopies 1
|
2021-01-06 18:11:08 +00:00
|
|
|
|
|
|
|
fromSourcesOr :: v -> [Annex (Maybe v)] -> Annex v
|
|
|
|
fromSourcesOr v = fromMaybe v <$$> getM id
|
2014-01-21 22:08:56 +00:00
|
|
|
|
|
|
|
{- The git config annex.numcopies is deprecated. -}
|
|
|
|
deprecatedNumCopies :: Annex (Maybe NumCopies)
|
|
|
|
deprecatedNumCopies = annexNumCopies <$> Annex.getGitConfig
|
|
|
|
|
|
|
|
{- Value forced on the command line by --numcopies. -}
|
|
|
|
getForcedNumCopies :: Annex (Maybe NumCopies)
|
2022-06-28 19:28:14 +00:00
|
|
|
getForcedNumCopies = Annex.getRead Annex.forcenumcopies
|
2014-01-21 22:08:56 +00:00
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
{- Value forced on the command line by --mincopies. -}
|
|
|
|
getForcedMinCopies :: Annex (Maybe MinCopies)
|
2022-06-28 19:28:14 +00:00
|
|
|
getForcedMinCopies = Annex.getRead Annex.forcemincopies
|
2021-01-06 18:11:08 +00:00
|
|
|
|
|
|
|
{- NumCopies value from any of the non-.gitattributes configuration
|
2014-01-21 22:08:56 +00:00
|
|
|
- sources. -}
|
|
|
|
getNumCopies :: Annex NumCopies
|
2021-01-06 18:11:08 +00:00
|
|
|
getNumCopies = fromSourcesOr defaultNumCopies
|
2014-01-21 22:08:56 +00:00
|
|
|
[ getForcedNumCopies
|
|
|
|
, getGlobalNumCopies
|
|
|
|
, deprecatedNumCopies
|
|
|
|
]
|
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
{- MinCopies value from any of the non-.gitattributes configuration
|
|
|
|
- sources. -}
|
|
|
|
getMinCopies :: Annex MinCopies
|
|
|
|
getMinCopies = fromSourcesOr defaultMinCopies
|
|
|
|
[ getForcedMinCopies
|
|
|
|
, getGlobalMinCopies
|
2014-01-21 22:08:56 +00:00
|
|
|
]
|
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
{- NumCopies and MinCopies value for a file, from any configuration source,
|
|
|
|
- including .gitattributes. -}
|
|
|
|
getFileNumMinCopies :: RawFilePath -> Annex (NumCopies, MinCopies)
|
|
|
|
getFileNumMinCopies f = do
|
|
|
|
fnumc <- getForcedNumCopies
|
|
|
|
fminc <- getForcedMinCopies
|
|
|
|
case (fnumc, fminc) of
|
|
|
|
(Just numc, Just minc) -> return (numc, minc)
|
|
|
|
(Just numc, Nothing) -> do
|
|
|
|
minc <- fromSourcesOr defaultMinCopies
|
|
|
|
[ snd <$> getNumMinCopiesAttr f
|
|
|
|
, getGlobalMinCopies
|
|
|
|
]
|
|
|
|
return (numc, minc)
|
|
|
|
(Nothing, Just minc) -> do
|
|
|
|
numc <- fromSourcesOr defaultNumCopies
|
|
|
|
[ fst <$> getNumMinCopiesAttr f
|
|
|
|
, getGlobalNumCopies
|
|
|
|
, deprecatedNumCopies
|
|
|
|
]
|
|
|
|
return (numc, minc)
|
|
|
|
(Nothing, Nothing) -> do
|
|
|
|
let fallbacknum = fromSourcesOr defaultNumCopies
|
|
|
|
[ getGlobalNumCopies
|
|
|
|
, deprecatedNumCopies
|
|
|
|
]
|
|
|
|
let fallbackmin = fromSourcesOr defaultMinCopies
|
|
|
|
[ getGlobalMinCopies
|
|
|
|
]
|
|
|
|
getNumMinCopiesAttr f >>= \case
|
|
|
|
(Just numc, Just minc) ->
|
|
|
|
return (numc, minc)
|
|
|
|
(Just numc, Nothing) -> (,)
|
|
|
|
<$> pure numc
|
|
|
|
<*> fallbackmin
|
|
|
|
(Nothing, Just minc) -> (,)
|
|
|
|
<$> fallbacknum
|
|
|
|
<*> pure minc
|
|
|
|
(Nothing, Nothing) -> (,)
|
|
|
|
<$> fallbacknum
|
|
|
|
<*> fallbackmin
|
|
|
|
|
2021-06-15 15:12:27 +00:00
|
|
|
{- Gets the highest NumCopies and MinCopies value for all files
|
|
|
|
- associated with a key. Provide any known associated file;
|
|
|
|
- the rest are looked up from the database.
|
|
|
|
-
|
2021-06-15 15:38:44 +00:00
|
|
|
- Using this when dropping, rather than getFileNumMinCopies
|
|
|
|
- avoids dropping one file that has a smaller value violating
|
|
|
|
- the value set for another file that uses the same content.
|
2021-06-15 15:12:27 +00:00
|
|
|
-}
|
|
|
|
getSafestNumMinCopies :: AssociatedFile -> Key -> Annex (NumCopies, MinCopies)
|
|
|
|
getSafestNumMinCopies afile k =
|
|
|
|
Database.Keys.getAssociatedFilesIncluding afile k
|
2021-06-15 15:38:44 +00:00
|
|
|
>>= getSafestNumMinCopies' afile k
|
2021-06-15 15:12:27 +00:00
|
|
|
|
2021-06-15 15:38:44 +00:00
|
|
|
getSafestNumMinCopies' :: AssociatedFile -> Key -> [RawFilePath] -> Annex (NumCopies, MinCopies)
|
|
|
|
getSafestNumMinCopies' afile k fs = do
|
2021-06-15 15:12:27 +00:00
|
|
|
l <- mapM getFileNumMinCopies fs
|
|
|
|
let l' = zip l fs
|
|
|
|
(,)
|
|
|
|
<$> findmax fst l' getNumCopies
|
|
|
|
<*> findmax snd l' getMinCopies
|
|
|
|
where
|
|
|
|
-- Some associated files in the keys database may no longer
|
|
|
|
-- correspond to files in the repository.
|
2021-06-15 15:38:44 +00:00
|
|
|
-- (But the AssociatedFile passed to this is known to be
|
|
|
|
-- an associated file, which may not be in the keys database
|
|
|
|
-- yet, so checking it is skipped.)
|
|
|
|
stillassociated f
|
|
|
|
| AssociatedFile (Just f) == afile = return True
|
|
|
|
| otherwise = catKeyFile f >>= \case
|
|
|
|
Just k' | k' == k -> return True
|
|
|
|
_ -> return False
|
2021-06-15 15:12:27 +00:00
|
|
|
|
|
|
|
-- Avoid calling stillassociated on every file; just make sure
|
|
|
|
-- that the one with the highest value is still associated.
|
|
|
|
findmax _ [] fallback = fallback
|
|
|
|
findmax getv l fallback = do
|
|
|
|
let n = maximum (map (getv . fst) l)
|
|
|
|
let (maxls, l') = partition (\(x, _) -> getv x == n) l
|
|
|
|
ifM (anyM stillassociated (map snd maxls))
|
|
|
|
( return n
|
|
|
|
, findmax getv l' fallback
|
|
|
|
)
|
|
|
|
|
2014-01-21 22:08:56 +00:00
|
|
|
{- This is the globally visible numcopies value for a file. So it does
|
|
|
|
- not include local configuration in the git config or command line
|
|
|
|
- options. -}
|
2020-10-30 19:55:59 +00:00
|
|
|
getGlobalFileNumCopies :: RawFilePath -> Annex NumCopies
|
2021-01-06 18:11:08 +00:00
|
|
|
getGlobalFileNumCopies f = fromSourcesOr defaultNumCopies
|
|
|
|
[ fst <$> getNumMinCopiesAttr f
|
|
|
|
, getGlobalNumCopies
|
2014-01-21 22:08:56 +00:00
|
|
|
]
|
|
|
|
|
2021-01-06 18:11:08 +00:00
|
|
|
getNumMinCopiesAttr :: RawFilePath -> Annex (Maybe NumCopies, Maybe MinCopies)
|
|
|
|
getNumMinCopiesAttr file =
|
|
|
|
checkAttrs ["annex.numcopies", "annex.mincopies"] file >>= \case
|
|
|
|
(n:m:[]) -> return
|
2022-03-28 19:19:52 +00:00
|
|
|
( configuredNumCopies <$> readish n
|
|
|
|
, configuredMinCopies <$> readish m
|
2021-01-06 18:11:08 +00:00
|
|
|
)
|
|
|
|
_ -> error "internal"
|
2014-01-21 22:08:56 +00:00
|
|
|
|
|
|
|
{- Checks if numcopies are satisfied for a file by running a comparison
|
|
|
|
- between the number of (not untrusted) copies that are
|
2023-03-13 22:55:18 +00:00
|
|
|
- believed to exist, and the configured value.
|
2015-10-08 22:20:36 +00:00
|
|
|
-
|
|
|
|
- This is good enough for everything except dropping the file, which
|
|
|
|
- requires active verification of the copies.
|
|
|
|
-}
|
2020-10-30 19:55:59 +00:00
|
|
|
numCopiesCheck :: RawFilePath -> Key -> (Int -> Int -> v) -> Annex v
|
2014-01-21 22:08:56 +00:00
|
|
|
numCopiesCheck file key vs = do
|
|
|
|
have <- trustExclude UnTrusted =<< Remote.keyLocations key
|
2015-04-12 16:49:11 +00:00
|
|
|
numCopiesCheck' file vs have
|
|
|
|
|
2020-10-30 19:55:59 +00:00
|
|
|
numCopiesCheck' :: RawFilePath -> (Int -> Int -> v) -> [UUID] -> Annex v
|
2015-04-12 16:49:11 +00:00
|
|
|
numCopiesCheck' file vs have = do
|
2024-06-16 19:07:48 +00:00
|
|
|
needed <- fst <$> getFileNumMinCopies file
|
2024-06-16 15:34:35 +00:00
|
|
|
let nhave = numCopiesCount have
|
2023-07-31 16:36:13 +00:00
|
|
|
explain (ActionItemTreeFile file) $ Just $ UnquotedString $
|
|
|
|
"has " ++ show nhave ++ " " ++ pluralCopies nhave ++
|
|
|
|
", and the configured annex.numcopies is " ++ show needed
|
2024-06-16 19:07:48 +00:00
|
|
|
return $ numCopiesCheck'' have vs needed
|
|
|
|
|
|
|
|
numCopiesCheck'' :: [UUID] -> (Int -> Int -> v) -> NumCopies -> v
|
|
|
|
numCopiesCheck'' have vs needed =
|
|
|
|
let nhave = numCopiesCount have
|
|
|
|
in nhave `vs` fromNumCopies needed
|
2015-04-30 18:02:56 +00:00
|
|
|
|
2024-06-16 15:34:35 +00:00
|
|
|
{- When a key is logged as present in a node of the cluster,
|
|
|
|
- the cluster's UUID will also be in the list, but is not a
|
|
|
|
- distinct copy.
|
|
|
|
-}
|
|
|
|
numCopiesCount :: [UUID] -> Int
|
|
|
|
numCopiesCount = length . filter (not . isClusterUUID)
|
|
|
|
|
2015-10-09 18:57:32 +00:00
|
|
|
data UnVerifiedCopy = UnVerifiedRemote Remote | UnVerifiedHere
|
|
|
|
deriving (Ord, Eq)
|
|
|
|
|
2023-03-14 02:39:16 +00:00
|
|
|
{- Verifies that enough copies of a key exist among the listed remotes,
|
2015-10-09 19:48:02 +00:00
|
|
|
- to safely drop it, running an action with a proof if so, and
|
|
|
|
- printing an informative message if not.
|
2015-04-30 18:02:56 +00:00
|
|
|
-}
|
2015-10-09 15:09:46 +00:00
|
|
|
verifyEnoughCopiesToDrop
|
2015-04-30 18:02:56 +00:00
|
|
|
:: String -- message to print when there are no known locations
|
|
|
|
-> Key
|
2024-06-23 13:28:18 +00:00
|
|
|
-> Maybe UUID -- repo dropping from
|
2015-10-09 19:48:02 +00:00
|
|
|
-> Maybe ContentRemovalLock
|
2015-04-30 18:02:56 +00:00
|
|
|
-> NumCopies
|
2021-01-06 18:11:08 +00:00
|
|
|
-> MinCopies
|
2015-06-03 17:15:38 +00:00
|
|
|
-> [UUID] -- repos to skip considering (generally untrusted remotes)
|
2015-10-08 22:20:36 +00:00
|
|
|
-> [VerifiedCopy] -- copies already verified to exist
|
2015-10-09 18:57:32 +00:00
|
|
|
-> [UnVerifiedCopy] -- places to check to see if they have copies
|
2015-10-09 20:16:03 +00:00
|
|
|
-> (SafeDropProof -> Annex a) -- action to perform the drop
|
2015-10-09 15:09:46 +00:00
|
|
|
-> Annex a -- action to perform when unable to drop
|
|
|
|
-> Annex a
|
2024-06-23 13:28:18 +00:00
|
|
|
verifyEnoughCopiesToDrop nolocmsg key dropfrom removallock neednum needmin skip preverified tocheck dropaction nodropaction =
|
2020-06-26 17:00:40 +00:00
|
|
|
helper [] [] preverified (nub tocheck) []
|
2015-04-30 18:02:56 +00:00
|
|
|
where
|
2020-06-26 17:00:40 +00:00
|
|
|
helper bad missing have [] lockunsupported =
|
2021-01-06 18:11:08 +00:00
|
|
|
liftIO (mkSafeDropProof neednum needmin have removallock) >>= \case
|
2015-10-09 15:09:46 +00:00
|
|
|
Right proof -> dropaction proof
|
|
|
|
Left stillhave -> do
|
2024-06-23 13:28:18 +00:00
|
|
|
notEnoughCopies key dropfrom neednum needmin stillhave (skip++missing) bad nolocmsg lockunsupported
|
2015-10-09 15:09:46 +00:00
|
|
|
nodropaction
|
2020-06-26 17:00:40 +00:00
|
|
|
helper bad missing have (c:cs) lockunsupported
|
2021-01-06 18:11:08 +00:00
|
|
|
| isSafeDrop neednum needmin have removallock =
|
|
|
|
liftIO (mkSafeDropProof neednum needmin have removallock) >>= \case
|
2015-10-09 15:09:46 +00:00
|
|
|
Right proof -> dropaction proof
|
2020-06-26 17:00:40 +00:00
|
|
|
Left stillhave -> helper bad missing stillhave (c:cs) lockunsupported
|
2015-10-09 18:57:32 +00:00
|
|
|
| otherwise = case c of
|
add content retention files
This allows lockContentShared to lock content for eg, 10 minutes and
if the process then gets terminated before it can unlock, the content
will remain locked for that amount of time.
The Windows implementation is not yet tested.
In P2P.Annex, a duration of 10 minutes is used. This way, when p2pstdio
or remotedaemon is serving the P2P protocol, and is asked to
LOCKCONTENT, and that process gets killed, the content will not be
subject to deletion. This is not a perfect solution to
doc/todo/P2P_locking_connection_drop_safety.mdwn yet, but it gets most
of the way there, without needing any P2P protocol changes.
This is only done in v10 and higher repositories (or on Windows). It
might be possible to backport it to v8 or earlier, but it would
complicate locking even further, and without a separate lock file, might
be hard. I think that by the time this fix reaches a given user, they
will probably have been running git-annex 10.x long enough that their v8
repositories will have upgraded to v10 after the 1 year wait. And it's
not as if git-annex hasn't already been subject to this problem (though
I have not heard of any data loss caused by it) for 6 years already, so
waiting another fraction of a year on top of however long it takes this
fix to reach users is unlikely to be a problem.
2024-07-03 18:44:38 +00:00
|
|
|
UnVerifiedHere -> lockContentShared key Nothing contverified
|
2024-06-16 15:34:35 +00:00
|
|
|
UnVerifiedRemote r
|
|
|
|
-- Skip cluster uuids because locking is
|
|
|
|
-- not supported with them, instead will
|
|
|
|
-- lock individual nodes.
|
|
|
|
| isClusterUUID (Remote.uuid r) -> helper bad missing have cs lockunsupported
|
|
|
|
| otherwise -> checkremote r contverified $
|
|
|
|
let lockunsupported' = r : lockunsupported
|
|
|
|
in Remote.hasKey r key >>= \case
|
|
|
|
Right True -> helper bad missing (mkVerifiedCopy RecentlyVerifiedCopy r : have) cs lockunsupported'
|
|
|
|
Left _ -> helper (r:bad) missing have cs lockunsupported'
|
|
|
|
Right False -> helper bad (Remote.uuid r:missing) have cs lockunsupported'
|
2015-10-09 18:57:32 +00:00
|
|
|
where
|
2020-06-26 17:00:40 +00:00
|
|
|
contverified vc = helper bad missing (vc : have) cs lockunsupported
|
2015-10-09 18:57:32 +00:00
|
|
|
|
|
|
|
checkremote r cont fallback = case Remote.lockContent r of
|
|
|
|
Just lockcontent -> do
|
|
|
|
-- The remote's lockContent will throw an exception
|
|
|
|
-- when it is unable to lock, in which case the
|
|
|
|
-- fallback should be run.
|
|
|
|
--
|
|
|
|
-- On the other hand, the continuation could itself
|
|
|
|
-- throw an exception (ie, the eventual drop action
|
|
|
|
-- fails), and in this case we don't want to run the
|
|
|
|
-- fallback since part of the drop action may have
|
|
|
|
-- already been performed.
|
|
|
|
--
|
|
|
|
-- Differentiate between these two sorts
|
|
|
|
-- of exceptions by using DropException.
|
|
|
|
let a = lockcontent key $ \v ->
|
|
|
|
cont v `catchNonAsync` (throw . DropException)
|
2024-06-23 10:20:11 +00:00
|
|
|
a `MC.catches`
|
|
|
|
[ MC.Handler (\ (e :: AsyncException) -> throwM e)
|
|
|
|
, MC.Handler (\ (e :: SomeAsyncException) -> throwM e)
|
|
|
|
, MC.Handler (\ (DropException e') -> throwM e')
|
|
|
|
, MC.Handler (\ (_e :: SomeException) -> fallback)
|
2015-10-09 18:57:32 +00:00
|
|
|
]
|
|
|
|
Nothing -> fallback
|
2015-04-30 18:02:56 +00:00
|
|
|
|
2015-10-09 17:07:03 +00:00
|
|
|
data DropException = DropException SomeException
|
|
|
|
deriving (Typeable, Show)
|
|
|
|
|
|
|
|
instance Exception DropException
|
|
|
|
|
2024-06-23 13:28:18 +00:00
|
|
|
notEnoughCopies :: Key -> Maybe UUID -> NumCopies -> MinCopies -> [VerifiedCopy] -> [UUID] -> [Remote] -> String -> [Remote] -> Annex ()
|
|
|
|
notEnoughCopies key dropfrom neednum needmin have skip bad nolocmsg lockunsupported = do
|
2015-04-30 18:02:56 +00:00
|
|
|
showNote "unsafe"
|
2021-01-06 18:11:08 +00:00
|
|
|
if length have < fromNumCopies neednum
|
2023-04-10 21:03:41 +00:00
|
|
|
then showLongNote $ UnquotedString $
|
2023-12-04 15:12:54 +00:00
|
|
|
if fromNumCopies neednum == 1
|
|
|
|
then "Could not verify the existence of the 1 necessary copy."
|
|
|
|
else "Could only verify the existence of " ++
|
|
|
|
show (length have) ++ " out of " ++ show (fromNumCopies neednum) ++
|
|
|
|
" necessary " ++ pluralCopies (fromNumCopies neednum) ++ "."
|
2015-10-09 19:14:25 +00:00
|
|
|
else do
|
2023-04-10 21:03:41 +00:00
|
|
|
showLongNote $ UnquotedString $ "Unable to lock down " ++ show (fromMinCopies needmin) ++
|
2023-07-31 16:36:13 +00:00
|
|
|
" " ++ pluralCopies (fromMinCopies needmin) ++
|
2021-04-27 17:39:56 +00:00
|
|
|
" of file necessary to safely drop it."
|
2020-06-26 17:00:40 +00:00
|
|
|
if null lockunsupported
|
|
|
|
then showLongNote "(This could have happened because of a concurrent drop, or because a remote has too old a version of git-annex-shell installed.)"
|
2023-04-10 21:03:41 +00:00
|
|
|
else showLongNote $ UnquotedString $ "These remotes do not support locking: "
|
2020-06-26 17:00:40 +00:00
|
|
|
++ Remote.listRemoteNames lockunsupported
|
|
|
|
|
2015-04-30 18:02:56 +00:00
|
|
|
Remote.showTriedRemotes bad
|
2024-06-23 13:28:18 +00:00
|
|
|
-- When dropping from a cluster, don't suggest making the nodes of
|
|
|
|
-- the cluster available
|
|
|
|
clusternodes <- case mkClusterUUID =<< dropfrom of
|
|
|
|
Nothing -> pure []
|
|
|
|
Just cu -> do
|
|
|
|
clusters <- getClusters
|
|
|
|
pure $ maybe [] (map fromClusterNodeUUID . S.toList) $
|
|
|
|
M.lookup cu (clusterUUIDs clusters)
|
|
|
|
let excludeset = S.fromList $ map toUUID have++skip++clusternodes
|
|
|
|
-- Don't suggest making a cluster available when dropping from its
|
|
|
|
-- node.
|
|
|
|
let exclude u
|
|
|
|
| u `S.member` excludeset = pure True
|
|
|
|
| otherwise = case (dropfrom, mkClusterUUID u) of
|
|
|
|
(Just dropfrom', Just cu) -> do
|
|
|
|
clusters <- getClusters
|
|
|
|
pure $ case M.lookup cu (clusterUUIDs clusters) of
|
|
|
|
Just nodes ->
|
|
|
|
ClusterNodeUUID dropfrom'
|
|
|
|
`S.member` nodes
|
|
|
|
Nothing -> False
|
|
|
|
_ -> pure False
|
|
|
|
Remote.showLocations True key exclude nolocmsg
|
2023-07-31 16:36:13 +00:00
|
|
|
|
|
|
|
pluralCopies :: Int -> String
|
|
|
|
pluralCopies 1 = "copy"
|
|
|
|
pluralCopies _ = "copies"
|
2015-04-30 18:02:56 +00:00
|
|
|
|
2015-10-09 18:57:32 +00:00
|
|
|
{- Finds locations of a key that can be used to get VerifiedCopies,
|
|
|
|
- in order to allow dropping the key.
|
|
|
|
-
|
|
|
|
- Provide a list of UUIDs that the key is being dropped from.
|
|
|
|
- The returned lists will exclude any of those UUIDs.
|
|
|
|
-
|
|
|
|
- The return lists also exclude any repositories that are untrusted,
|
|
|
|
- since those should not be used for verification.
|
2015-04-30 18:02:56 +00:00
|
|
|
-
|
2024-06-23 10:20:11 +00:00
|
|
|
- When dropping from a cluster UUID, its nodes are excluded.
|
|
|
|
-
|
|
|
|
- Cluster UUIDs are also excluded since locking a key on a cluster
|
|
|
|
- is done by locking on individual nodes.
|
2024-06-16 15:34:35 +00:00
|
|
|
-
|
2015-10-09 18:57:32 +00:00
|
|
|
- The UnVerifiedCopy list is cost ordered.
|
|
|
|
- The VerifiedCopy list contains repositories that are trusted to
|
|
|
|
- contain the key.
|
2015-04-30 18:02:56 +00:00
|
|
|
-}
|
2015-10-09 18:57:32 +00:00
|
|
|
verifiableCopies :: Key -> [UUID] -> Annex ([UnVerifiedCopy], [VerifiedCopy])
|
|
|
|
verifiableCopies key exclude = do
|
2024-06-16 15:34:35 +00:00
|
|
|
locs <- filter (not . isClusterUUID) <$> Remote.keyLocations key
|
2023-11-30 19:11:57 +00:00
|
|
|
(remotes, trusteduuids) <- Remote.remoteLocations (Remote.IncludeIgnored False) locs
|
2015-10-09 18:57:32 +00:00
|
|
|
=<< trustGet Trusted
|
2024-06-23 10:20:11 +00:00
|
|
|
clusternodes <- if any isClusterUUID exclude
|
|
|
|
then do
|
|
|
|
clusters <- getClusters
|
|
|
|
pure $ concatMap (getclusternodes clusters) exclude
|
|
|
|
else pure []
|
2015-10-09 18:57:32 +00:00
|
|
|
untrusteduuids <- trustGet UnTrusted
|
2024-06-23 10:20:11 +00:00
|
|
|
let exclude' = exclude ++ untrusteduuids ++ clusternodes
|
2015-10-09 18:57:32 +00:00
|
|
|
let remotes' = Remote.remotesWithoutUUID remotes (exclude' ++ trusteduuids)
|
|
|
|
let verified = map (mkVerifiedCopy TrustedCopy) $
|
|
|
|
filter (`notElem` exclude') trusteduuids
|
2015-04-30 18:02:56 +00:00
|
|
|
u <- getUUID
|
2015-10-09 18:57:32 +00:00
|
|
|
let herec = if u `elem` locs && u `notElem` exclude'
|
|
|
|
then [UnVerifiedHere]
|
|
|
|
else []
|
|
|
|
return (herec ++ map UnVerifiedRemote remotes', verified)
|
2024-06-23 10:20:11 +00:00
|
|
|
where
|
|
|
|
getclusternodes clusters u = case mkClusterUUID u of
|
|
|
|
Just cu -> maybe [] (map fromClusterNodeUUID . S.toList) $
|
|
|
|
M.lookup cu (clusterUUIDs clusters)
|
|
|
|
Nothing -> []
|