2011-09-18 21:47:49 +00:00
|
|
|
{- user-specified limits on files to act on
|
|
|
|
-
|
2024-08-09 18:16:09 +00:00
|
|
|
- Copyright 2011-2024 Joey Hess <id@joeyh.name>
|
2011-09-18 21:47:49 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-09-18 21:47:49 +00:00
|
|
|
-}
|
|
|
|
|
2021-05-25 17:05:42 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2011-09-18 21:47:49 +00:00
|
|
|
module Limit where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2011-10-04 02:24:57 +00:00
|
|
|
import qualified Annex
|
2011-09-18 21:47:49 +00:00
|
|
|
import qualified Utility.Matcher
|
2011-09-19 00:14:18 +00:00
|
|
|
import qualified Remote
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2015-12-15 19:34:28 +00:00
|
|
|
import Annex.WorkTree
|
2012-10-05 20:52:44 +00:00
|
|
|
import Annex.UUID
|
2019-01-23 16:39:02 +00:00
|
|
|
import Annex.Magic
|
2024-08-13 15:00:20 +00:00
|
|
|
import Annex.RepoSize
|
2024-08-24 15:49:58 +00:00
|
|
|
import Annex.RepoSize.LiveUpdate
|
2024-08-13 15:00:20 +00:00
|
|
|
import Logs.MaxSize
|
2019-09-19 15:32:12 +00:00
|
|
|
import Annex.Link
|
2021-03-02 16:47:23 +00:00
|
|
|
import Types.Link
|
2012-09-23 17:50:31 +00:00
|
|
|
import Logs.Trust
|
2015-04-30 18:02:56 +00:00
|
|
|
import Annex.NumCopies
|
2017-02-24 19:16:56 +00:00
|
|
|
import Types.Key
|
2012-10-03 21:04:52 +00:00
|
|
|
import Types.TrustLevel
|
2012-10-08 19:18:58 +00:00
|
|
|
import Types.Group
|
2013-05-25 03:07:26 +00:00
|
|
|
import Types.FileMatcher
|
2014-02-13 06:24:30 +00:00
|
|
|
import Types.MetaData
|
2016-02-27 14:55:02 +00:00
|
|
|
import Annex.MetaData
|
2014-02-13 06:24:30 +00:00
|
|
|
import Logs.MetaData
|
2012-10-01 22:25:11 +00:00
|
|
|
import Logs.Group
|
2014-01-22 20:35:32 +00:00
|
|
|
import Logs.Unused
|
2014-02-06 16:43:56 +00:00
|
|
|
import Logs.Location
|
2021-05-25 17:05:42 +00:00
|
|
|
import Annex.CatFile
|
|
|
|
import Git.FilePath
|
2014-02-06 16:43:56 +00:00
|
|
|
import Git.Types (RefDate(..))
|
2014-02-21 22:34:34 +00:00
|
|
|
import Utility.Glob
|
2012-09-25 20:48:24 +00:00
|
|
|
import Utility.HumanTime
|
2012-10-08 17:39:18 +00:00
|
|
|
import Utility.DataUnits
|
2021-05-25 17:05:42 +00:00
|
|
|
import qualified Database.Keys
|
2019-12-11 18:12:22 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
2020-07-20 16:08:37 +00:00
|
|
|
import Backend
|
2011-09-18 21:47:49 +00:00
|
|
|
|
2023-07-25 20:11:06 +00:00
|
|
|
import Control.Monad.Writer
|
2014-02-11 05:35:11 +00:00
|
|
|
import Data.Time.Clock.POSIX
|
|
|
|
import qualified Data.Set as S
|
|
|
|
import qualified Data.Map as M
|
2021-05-25 17:05:42 +00:00
|
|
|
import qualified System.FilePath.ByteString as P
|
2023-03-01 19:55:58 +00:00
|
|
|
import System.PosixCompat.Files (accessTime, isSymbolicLink)
|
2013-05-26 22:14:03 +00:00
|
|
|
|
2019-09-30 21:12:47 +00:00
|
|
|
{- Some limits can look at the current status of files on
|
|
|
|
- disk, or in the annex. This allows controlling which happens. -}
|
|
|
|
data LimitBy = LimitDiskFiles | LimitAnnexFiles
|
|
|
|
|
2011-09-19 00:41:51 +00:00
|
|
|
{- Checks if there are user-specified limits. -}
|
|
|
|
limited :: Annex Bool
|
2012-12-06 17:22:16 +00:00
|
|
|
limited = (not . Utility.Matcher.isEmpty) <$> getMatcher'
|
2011-09-19 00:41:51 +00:00
|
|
|
|
2011-09-18 21:47:49 +00:00
|
|
|
{- Gets a matcher for the user-specified limits. The matcher is cached for
|
|
|
|
- speed; once it's obtained the user-specified limits can't change. -}
|
2014-01-18 18:51:55 +00:00
|
|
|
getMatcher :: Annex (MatchInfo -> Annex Bool)
|
2020-09-24 17:55:19 +00:00
|
|
|
getMatcher = run <$> getMatcher'
|
|
|
|
where
|
2023-07-25 20:11:06 +00:00
|
|
|
run matcher i = do
|
|
|
|
(match, desc) <- runWriterT $
|
|
|
|
Utility.Matcher.matchMrun' matcher $ \o ->
|
2024-08-23 20:35:12 +00:00
|
|
|
matchAction o NoLiveUpdate S.empty i
|
2023-07-26 18:34:21 +00:00
|
|
|
explain (mkActionItem i) $ UnquotedString <$>
|
|
|
|
Utility.Matcher.describeMatchResult matchDesc desc
|
|
|
|
(if match then "matches:" else "does not match:")
|
2023-07-25 20:11:06 +00:00
|
|
|
return match
|
|
|
|
|
2020-09-24 17:55:19 +00:00
|
|
|
getMatcher' :: Annex (Utility.Matcher.Matcher (MatchFiles Annex))
|
2014-03-29 18:43:34 +00:00
|
|
|
getMatcher' = go =<< Annex.getState Annex.limit
|
|
|
|
where
|
|
|
|
go (CompleteMatcher matcher) = return matcher
|
|
|
|
go (BuildingMatcher l) = do
|
|
|
|
let matcher = Utility.Matcher.generate (reverse l)
|
|
|
|
Annex.changeState $ \s ->
|
|
|
|
s { Annex.limit = CompleteMatcher matcher }
|
|
|
|
return matcher
|
2011-09-18 21:47:49 +00:00
|
|
|
|
2020-09-24 20:08:47 +00:00
|
|
|
{- Checks if the user-specified limits contains anything that meets the
|
|
|
|
- condition. -}
|
|
|
|
introspect :: (MatchFiles Annex -> Bool) -> Annex Bool
|
2020-09-28 17:22:16 +00:00
|
|
|
introspect c = Utility.Matcher.introspect c <$> getMatcher'
|
2020-09-24 20:08:47 +00:00
|
|
|
|
2011-09-18 22:21:42 +00:00
|
|
|
{- Adds something to the limit list, which is built up reversed. -}
|
2020-09-24 17:55:19 +00:00
|
|
|
add :: Utility.Matcher.Token (MatchFiles Annex) -> Annex ()
|
2011-09-19 05:57:12 +00:00
|
|
|
add l = Annex.changeState $ \s -> s { Annex.limit = prepend $ Annex.limit s }
|
2012-10-29 02:09:09 +00:00
|
|
|
where
|
2020-09-24 17:55:19 +00:00
|
|
|
prepend (BuildingMatcher ls) = BuildingMatcher (l:ls)
|
2012-10-29 02:09:09 +00:00
|
|
|
prepend _ = error "internal"
|
2011-09-18 21:47:49 +00:00
|
|
|
|
2019-05-14 17:08:51 +00:00
|
|
|
{- Adds a new syntax token. -}
|
|
|
|
addSyntaxToken :: String -> Annex ()
|
2023-04-10 17:38:14 +00:00
|
|
|
addSyntaxToken = either giveup add . Utility.Matcher.syntaxToken
|
2011-09-20 04:49:40 +00:00
|
|
|
|
|
|
|
{- Adds a new limit. -}
|
2014-03-29 18:43:34 +00:00
|
|
|
addLimit :: Either String (MatchFiles Annex) -> Annex ()
|
2020-09-24 17:55:19 +00:00
|
|
|
addLimit = either giveup (add . Utility.Matcher.Operation)
|
2011-09-18 21:47:49 +00:00
|
|
|
|
|
|
|
{- Add a limit to skip files that do not match the glob. -}
|
2011-12-22 17:53:06 +00:00
|
|
|
addInclude :: String -> Annex ()
|
2012-10-04 19:48:59 +00:00
|
|
|
addInclude = addLimit . limitInclude
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
limitInclude :: MkLimit Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitInclude glob = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ matchGlobFile glob
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "include" =? glob
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2011-12-22 17:53:06 +00:00
|
|
|
|
|
|
|
{- Add a limit to skip files that match the glob. -}
|
2011-09-19 00:14:18 +00:00
|
|
|
addExclude :: String -> Annex ()
|
2012-10-04 19:48:59 +00:00
|
|
|
addExclude = addLimit . limitExclude
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
limitExclude :: MkLimit Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitExclude glob = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ not <$$> matchGlobFile glob
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "exclude" =? glob
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2014-02-21 22:34:34 +00:00
|
|
|
|
2016-01-25 20:16:18 +00:00
|
|
|
matchGlobFile :: String -> MatchInfo -> Annex Bool
|
2014-02-21 22:34:34 +00:00
|
|
|
matchGlobFile glob = go
|
2016-02-03 20:29:34 +00:00
|
|
|
where
|
2023-03-13 23:06:23 +00:00
|
|
|
cglob = compileGlob glob CaseSensitive (GlobFilePath True) -- memoized
|
2019-12-09 17:49:05 +00:00
|
|
|
go (MatchingFile fi) = pure $ matchGlob cglob (fromRawFilePath (matchFile fi))
|
2021-03-02 16:47:23 +00:00
|
|
|
go (MatchingInfo p) = pure $ case providedFilePath p of
|
|
|
|
Just f -> matchGlob cglob (fromRawFilePath f)
|
|
|
|
Nothing -> False
|
2020-09-28 16:06:10 +00:00
|
|
|
go (MatchingUserInfo p) = matchGlob cglob <$> getUserInfo (userProvidedFilePath p)
|
2016-02-03 20:29:34 +00:00
|
|
|
|
2021-05-25 17:05:42 +00:00
|
|
|
{- Add a limit to skip files when there is no other file using the same
|
|
|
|
- content, with a name matching the glob. -}
|
|
|
|
addIncludeSameContent :: String -> Annex ()
|
|
|
|
addIncludeSameContent = addLimit . limitIncludeSameContent
|
|
|
|
|
|
|
|
limitIncludeSameContent :: MkLimit Annex
|
|
|
|
limitIncludeSameContent glob = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ matchSameContentGlob glob
|
2021-05-25 17:05:42 +00:00
|
|
|
, matchNeedsFileName = True
|
|
|
|
, matchNeedsFileContent = False
|
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "includesamecontent" =? glob
|
2021-05-25 17:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{- Add a limit to skip files when there is no other file using the same
|
|
|
|
- content, with a name matching the glob. -}
|
|
|
|
addExcludeSameContent :: String -> Annex ()
|
|
|
|
addExcludeSameContent = addLimit . limitExcludeSameContent
|
|
|
|
|
|
|
|
limitExcludeSameContent :: MkLimit Annex
|
|
|
|
limitExcludeSameContent glob = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ not <$$> matchSameContentGlob glob
|
2021-05-25 17:05:42 +00:00
|
|
|
, matchNeedsFileName = True
|
|
|
|
, matchNeedsFileContent = False
|
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "excludesamecontent" =? glob
|
2021-05-25 17:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
matchSameContentGlob :: String -> MatchInfo -> Annex Bool
|
|
|
|
matchSameContentGlob glob mi = checkKey (go mi) mi
|
|
|
|
where
|
|
|
|
go (MatchingFile fi) k = check k (matchFile fi)
|
|
|
|
go (MatchingInfo p) k = case providedFilePath p of
|
|
|
|
Just f -> check k f
|
|
|
|
Nothing -> return False
|
|
|
|
go (MatchingUserInfo p) k =
|
|
|
|
check k . toRawFilePath
|
|
|
|
=<< getUserInfo (userProvidedFilePath p)
|
|
|
|
|
2023-03-13 23:06:23 +00:00
|
|
|
cglob = compileGlob glob CaseSensitive (GlobFilePath True) -- memoized
|
2021-05-25 17:05:42 +00:00
|
|
|
|
|
|
|
matchesglob f = matchGlob cglob (fromRawFilePath f)
|
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
|| matchGlob cglob (fromRawFilePath (toInternalGitPath f))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
check k skipf = do
|
|
|
|
-- Find other files with the same content, with filenames
|
|
|
|
-- matching the glob.
|
|
|
|
g <- Annex.gitRepo
|
|
|
|
fs <- filter (/= P.normalise skipf)
|
|
|
|
. filter matchesglob
|
|
|
|
. map (\f -> P.normalise (fromTopFilePath f g))
|
|
|
|
<$> Database.Keys.getAssociatedFiles k
|
|
|
|
-- Some associated files in the keys database may no longer
|
|
|
|
-- correspond to files in the repository. This is checked
|
|
|
|
-- last as it's most expensive.
|
|
|
|
anyM (\f -> maybe False (== k) <$> catKeyFile f) fs
|
|
|
|
|
2019-09-19 15:32:12 +00:00
|
|
|
addMimeType :: String -> Annex ()
|
2020-09-28 16:06:10 +00:00
|
|
|
addMimeType = addMagicLimit "mimetype" getMagicMimeType providedMimeType userProvidedMimeType
|
2019-09-19 15:32:12 +00:00
|
|
|
|
|
|
|
addMimeEncoding :: String -> Annex ()
|
2020-09-28 16:06:10 +00:00
|
|
|
addMimeEncoding = addMagicLimit "mimeencoding" getMagicMimeEncoding providedMimeEncoding userProvidedMimeEncoding
|
|
|
|
|
|
|
|
addMagicLimit
|
|
|
|
:: String
|
|
|
|
-> (Magic -> FilePath -> Annex (Maybe String))
|
|
|
|
-> (ProvidedInfo -> Maybe String)
|
|
|
|
-> (UserProvidedInfo -> UserInfo String)
|
|
|
|
-> String
|
|
|
|
-> Annex ()
|
|
|
|
addMagicLimit limitname querymagic selectprovidedinfo selectuserprovidedinfo glob = do
|
2019-09-19 15:32:12 +00:00
|
|
|
magic <- liftIO initMagicMime
|
2020-09-28 16:06:10 +00:00
|
|
|
addLimit $ matchMagic limitname querymagic' selectprovidedinfo selectuserprovidedinfo magic glob
|
2019-09-19 15:32:12 +00:00
|
|
|
where
|
2019-11-26 19:27:22 +00:00
|
|
|
querymagic' magic f = liftIO (isPointerFile (toRawFilePath f)) >>= \case
|
2019-09-19 15:32:12 +00:00
|
|
|
-- Avoid getting magic of a pointer file, which would
|
|
|
|
-- wrongly be detected as text.
|
|
|
|
Just _ -> return Nothing
|
|
|
|
-- When the file is an annex symlink, get magic of the
|
|
|
|
-- object file.
|
2019-11-26 19:27:22 +00:00
|
|
|
Nothing -> isAnnexLink (toRawFilePath f) >>= \case
|
2019-12-11 18:12:22 +00:00
|
|
|
Just k -> withObjectLoc k $
|
|
|
|
querymagic magic . fromRawFilePath
|
2019-09-19 15:32:12 +00:00
|
|
|
Nothing -> querymagic magic f
|
|
|
|
|
2020-09-28 16:06:10 +00:00
|
|
|
matchMagic
|
|
|
|
:: String
|
|
|
|
-> (Magic -> FilePath -> Annex (Maybe String))
|
|
|
|
-> (ProvidedInfo -> Maybe String)
|
|
|
|
-> (UserProvidedInfo -> UserInfo String)
|
|
|
|
-> Maybe Magic
|
|
|
|
-> MkLimit Annex
|
2023-07-25 20:11:06 +00:00
|
|
|
matchMagic limitname querymagic selectprovidedinfo selectuserprovidedinfo (Just magic) glob =
|
2020-09-24 17:55:19 +00:00
|
|
|
Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const go
|
2021-03-01 20:10:42 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = True
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = limitname =? glob
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2016-02-03 20:29:34 +00:00
|
|
|
where
|
2023-03-13 23:06:23 +00:00
|
|
|
cglob = compileGlob glob CaseSensitive (GlobFilePath False) -- memoized
|
2021-03-01 20:34:40 +00:00
|
|
|
go (MatchingFile fi) = catchBoolIO $
|
|
|
|
maybe False (matchGlob cglob)
|
|
|
|
<$> querymagic magic (fromRawFilePath (contentFile fi))
|
2021-03-02 16:47:23 +00:00
|
|
|
go (MatchingInfo p) = maybe
|
|
|
|
(usecontent (providedKey p))
|
|
|
|
(pure . matchGlob cglob)
|
|
|
|
(selectprovidedinfo p)
|
2020-09-28 16:06:10 +00:00
|
|
|
go (MatchingUserInfo p) =
|
|
|
|
matchGlob cglob <$> getUserInfo (selectuserprovidedinfo p)
|
2021-03-02 16:47:23 +00:00
|
|
|
usecontent (Just k) = withObjectLoc k $ \obj -> catchBoolIO $
|
|
|
|
maybe False (matchGlob cglob)
|
|
|
|
<$> querymagic magic (fromRawFilePath obj)
|
|
|
|
usecontent Nothing = pure False
|
2020-09-28 16:06:10 +00:00
|
|
|
matchMagic limitname _ _ _ Nothing _ =
|
2019-04-30 15:58:06 +00:00
|
|
|
Left $ "unable to load magic database; \""++limitname++"\" cannot be used"
|
2011-09-19 00:14:18 +00:00
|
|
|
|
2019-09-19 16:20:35 +00:00
|
|
|
addUnlocked :: Annex ()
|
2020-09-24 17:55:19 +00:00
|
|
|
addUnlocked = addLimit $ Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ matchLockStatus False
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "unlocked"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2019-09-19 16:20:35 +00:00
|
|
|
|
|
|
|
addLocked :: Annex ()
|
2020-09-24 17:55:19 +00:00
|
|
|
addLocked = addLimit $ Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ matchLockStatus True
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "locked"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2019-09-19 16:20:35 +00:00
|
|
|
|
|
|
|
matchLockStatus :: Bool -> MatchInfo -> Annex Bool
|
2021-03-01 20:34:40 +00:00
|
|
|
matchLockStatus wantlocked (MatchingFile fi) = liftIO $ do
|
|
|
|
let f = contentFile fi
|
|
|
|
islocked <- isPointerFile f >>= \case
|
|
|
|
Just _key -> return False
|
|
|
|
Nothing -> isSymbolicLink
|
2023-03-01 19:55:58 +00:00
|
|
|
<$> R.getSymbolicLinkStatus f
|
2021-03-01 20:34:40 +00:00
|
|
|
return (islocked == wantlocked)
|
2021-03-02 16:47:23 +00:00
|
|
|
matchLockStatus wantlocked (MatchingInfo p) =
|
|
|
|
pure $ case providedLinkType p of
|
|
|
|
Nothing -> False
|
|
|
|
Just LockedLink -> wantlocked
|
|
|
|
Just UnlockedLink -> not wantlocked
|
|
|
|
matchLockStatus _ (MatchingUserInfo _) = pure False
|
2019-09-19 16:20:35 +00:00
|
|
|
|
2011-09-19 00:14:18 +00:00
|
|
|
{- Adds a limit to skip files not believed to be present
|
2023-03-14 02:39:16 +00:00
|
|
|
- in a specified repository. Optionally on a prior date. -}
|
2011-09-19 00:14:18 +00:00
|
|
|
addIn :: String -> Annex ()
|
2019-08-01 04:17:02 +00:00
|
|
|
addIn s = do
|
|
|
|
u <- Remote.nameToUUID name
|
|
|
|
hereu <- getUUID
|
|
|
|
addLimit $ if u == hereu && null date
|
2020-09-25 14:55:03 +00:00
|
|
|
then use True checkinhere
|
|
|
|
else use False (checkinuuid u)
|
2012-10-29 02:09:09 +00:00
|
|
|
where
|
2014-02-06 16:43:56 +00:00
|
|
|
(name, date) = separate (== '@') s
|
2020-09-24 21:59:05 +00:00
|
|
|
use inhere a = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ checkKey . a
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = not inhere
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "in" =? s
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2020-09-25 14:55:03 +00:00
|
|
|
checkinuuid u notpresent key
|
2014-02-06 16:43:56 +00:00
|
|
|
| null date = do
|
|
|
|
us <- Remote.keyLocations key
|
|
|
|
return $ u `elem` us && u `S.notMember` notpresent
|
|
|
|
| otherwise = do
|
|
|
|
us <- loggedLocationsHistorical (RefDate date) key
|
|
|
|
return $ u `elem` us
|
2020-09-25 14:55:03 +00:00
|
|
|
checkinhere notpresent key
|
2012-10-29 02:09:09 +00:00
|
|
|
| S.null notpresent = inAnnex key
|
|
|
|
| otherwise = do
|
|
|
|
u <- getUUID
|
|
|
|
if u `S.member` notpresent
|
|
|
|
then return False
|
|
|
|
else inAnnex key
|
2011-09-19 00:23:08 +00:00
|
|
|
|
2024-01-25 16:56:41 +00:00
|
|
|
{- Limit to content that location tracking expects to be present
|
|
|
|
- in the current repository. Does not verify inAnnex. -}
|
|
|
|
addExpectedPresent :: Annex ()
|
|
|
|
addExpectedPresent = do
|
|
|
|
hereu <- getUUID
|
|
|
|
addLimit $ Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey $ \key -> do
|
2024-01-25 16:56:41 +00:00
|
|
|
us <- Remote.keyLocations key
|
|
|
|
return $ hereu `elem` us
|
|
|
|
, matchNeedsFileName = False
|
|
|
|
, matchNeedsFileContent = False
|
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = True
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2024-01-25 16:56:41 +00:00
|
|
|
, matchDesc = matchDescSimple "expected-present"
|
|
|
|
}
|
|
|
|
|
2012-10-19 20:09:21 +00:00
|
|
|
{- Limit to content that is currently present on a uuid. -}
|
2016-02-03 17:23:34 +00:00
|
|
|
limitPresent :: Maybe UUID -> MatchFiles Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitPresent u = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey $ \key -> do
|
2020-09-24 17:55:19 +00:00
|
|
|
hereu <- getUUID
|
|
|
|
if u == Just hereu || isNothing u
|
|
|
|
then inAnnex key
|
|
|
|
else do
|
|
|
|
us <- Remote.keyLocations key
|
|
|
|
return $ maybe False (`elem` us) u
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = not (isNothing u)
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "present"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2012-10-19 20:09:21 +00:00
|
|
|
|
2013-04-26 03:44:55 +00:00
|
|
|
{- Limit to content that is in a directory, anywhere in the repository tree -}
|
2023-07-25 20:11:06 +00:00
|
|
|
limitInDir :: FilePath -> String -> MatchFiles Annex
|
|
|
|
limitInDir dir desc = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const go
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple desc
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2014-01-18 18:51:55 +00:00
|
|
|
where
|
2019-12-09 17:49:05 +00:00
|
|
|
go (MatchingFile fi) = checkf $ fromRawFilePath $ matchFile fi
|
2021-03-02 16:47:23 +00:00
|
|
|
go (MatchingInfo p) = maybe (pure False) (checkf . fromRawFilePath) (providedFilePath p)
|
2020-09-28 16:06:10 +00:00
|
|
|
go (MatchingUserInfo p) = checkf =<< getUserInfo (userProvidedFilePath p)
|
2016-01-25 20:16:18 +00:00
|
|
|
checkf = return . elem dir . splitPath . takeDirectory
|
2013-04-26 03:44:55 +00:00
|
|
|
|
2011-09-19 00:23:08 +00:00
|
|
|
{- Adds a limit to skip files not believed to have the specified number
|
|
|
|
- of copies. -}
|
|
|
|
addCopies :: String -> Annex ()
|
2012-10-04 19:48:59 +00:00
|
|
|
addCopies = addLimit . limitCopies
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
limitCopies :: MkLimit Annex
|
2017-01-31 22:40:42 +00:00
|
|
|
limitCopies want = case splitc ':' want of
|
2018-06-04 16:12:56 +00:00
|
|
|
-- Note that in case of a group having the same name as a trust
|
|
|
|
-- level, it's parsed as a trust level, not as a group.
|
2013-04-03 03:40:13 +00:00
|
|
|
[v, n] -> case parsetrustspec v of
|
2013-04-03 21:44:34 +00:00
|
|
|
Just checker -> go n $ checktrust checker
|
2019-01-09 19:00:43 +00:00
|
|
|
Nothing -> go n $ checkgroup (toGroup v)
|
2012-10-04 19:48:59 +00:00
|
|
|
[n] -> go n $ const $ return True
|
|
|
|
_ -> Left "bad value for copies"
|
2012-10-29 02:09:09 +00:00
|
|
|
where
|
|
|
|
go num good = case readish num of
|
|
|
|
Nothing -> Left "bad number for copies"
|
2020-09-24 17:55:19 +00:00
|
|
|
Just n -> Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ \notpresent -> checkKey $
|
2020-09-24 17:55:19 +00:00
|
|
|
go' n good notpresent
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = True
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "copies" =? want
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
unify exception handling into Utility.Exception
Removed old extensible-exceptions, only needed for very old ghc.
Made webdav use Utility.Exception, to work after some changes in DAV's
exception handling.
Removed Annex.Exception. Mostly this was trivial, but note that
tryAnnex is replaced with tryNonAsync and catchAnnex replaced with
catchNonAsync. In theory that could be a behavior change, since the former
caught all exceptions, and the latter don't catch async exceptions.
However, in practice, nothing in the Annex monad uses async exceptions.
Grepping for throwTo and killThread only find stuff in the assistant,
which does not seem related.
Command.Add.undo is changed to accept a SomeException, and things
that use it for rollback now catch non-async exceptions, rather than
only IOExceptions.
2014-08-08 01:55:44 +00:00
|
|
|
go' n good notpresent key = do
|
2012-10-29 02:09:09 +00:00
|
|
|
us <- filter (`S.notMember` notpresent)
|
|
|
|
<$> (filterM good =<< Remote.keyLocations key)
|
2024-06-16 19:07:48 +00:00
|
|
|
return $ numCopiesCount us >= n
|
2013-04-03 21:44:34 +00:00
|
|
|
checktrust checker u = checker <$> lookupTrust u
|
2012-10-29 02:09:09 +00:00
|
|
|
checkgroup g u = S.member g <$> lookupGroups u
|
2013-04-03 03:40:13 +00:00
|
|
|
parsetrustspec s
|
2018-04-13 19:16:07 +00:00
|
|
|
| "+" `isSuffixOf` s = (<=) <$> readTrustLevel (beginning s)
|
2013-04-03 03:40:13 +00:00
|
|
|
| otherwise = (==) <$> readTrustLevel s
|
2011-11-28 21:37:15 +00:00
|
|
|
|
2014-01-21 22:46:39 +00:00
|
|
|
{- Adds a limit to match files that need more copies made. -}
|
2023-07-25 20:11:06 +00:00
|
|
|
addLackingCopies :: String -> Bool -> String -> Annex ()
|
|
|
|
addLackingCopies desc approx = addLimit . limitLackingCopies desc approx
|
2014-01-21 22:46:39 +00:00
|
|
|
|
2023-07-25 20:11:06 +00:00
|
|
|
limitLackingCopies :: String -> Bool -> MkLimit Annex
|
|
|
|
limitLackingCopies desc approx want = case readish want of
|
2020-09-24 17:55:19 +00:00
|
|
|
Just needed -> Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ \notpresent mi -> flip checkKey mi $
|
2020-09-24 17:55:19 +00:00
|
|
|
go mi needed notpresent
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = True
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple desc
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2014-01-21 22:46:39 +00:00
|
|
|
Nothing -> Left "bad value for number of lacking copies"
|
Add and use numcopiesneeded preferred content expression.
* Add numcopiesneeded preferred content expression.
* Client, transfer, incremental backup, and archive repositories
now want to get content that does not yet have enough copies.
This means the asssistant will make copies of files that don't yet
meet the configured numcopies, even to places that would not normally want
the file.
For example, if numcopies is 4, and there are 2 client repos and
2 transfer repos, and 2 removable backup drives, the file will be sent
to both transfer repos in order to make 4 copies. Once a removable drive
get a copy of the file, it will be dropped from one transfer repo or the
other (but not both).
Another example, numcopies is 3 and there is a client that has a backup
removable drive and two small archive repos. Normally once one of the small
archives has a file, it will not be put into the other one. But, to satisfy
numcopies, the assistant will duplicate it into the other small archive
too, if the backup repo is not available to receive the file.
I notice that these examples are fairly unlikely setups .. the old behavior
was not too bad, but it's nice to finally have it really correct.
.. Almost. I have skipped checking the annex.numcopies .gitattributes
out of fear it will be too slow.
This commit was sponsored by Florian Schlegel.
2014-01-20 21:34:58 +00:00
|
|
|
where
|
unify exception handling into Utility.Exception
Removed old extensible-exceptions, only needed for very old ghc.
Made webdav use Utility.Exception, to work after some changes in DAV's
exception handling.
Removed Annex.Exception. Mostly this was trivial, but note that
tryAnnex is replaced with tryNonAsync and catchAnnex replaced with
catchNonAsync. In theory that could be a behavior change, since the former
caught all exceptions, and the latter don't catch async exceptions.
However, in practice, nothing in the Annex monad uses async exceptions.
Grepping for throwTo and killThread only find stuff in the assistant,
which does not seem related.
Command.Add.undo is changed to accept a SomeException, and things
that use it for rollback now catch non-async exceptions, rather than
only IOExceptions.
2014-08-08 01:55:44 +00:00
|
|
|
go mi needed notpresent key = do
|
2022-03-28 19:19:52 +00:00
|
|
|
numcopies <- if approx
|
2014-01-21 22:46:39 +00:00
|
|
|
then approxNumCopies
|
|
|
|
else case mi of
|
2019-12-09 17:49:05 +00:00
|
|
|
MatchingFile fi -> getGlobalFileNumCopies $
|
2020-10-30 19:55:59 +00:00
|
|
|
matchFile fi
|
2019-04-30 15:58:06 +00:00
|
|
|
MatchingInfo {} -> approxNumCopies
|
2020-09-28 16:06:10 +00:00
|
|
|
MatchingUserInfo {} -> approxNumCopies
|
2014-01-21 22:46:39 +00:00
|
|
|
us <- filter (`S.notMember` notpresent)
|
|
|
|
<$> (trustExclude UnTrusted =<< Remote.keyLocations key)
|
2024-06-16 19:07:48 +00:00
|
|
|
let vs nhave numcopies' = numcopies' - nhave >= needed
|
|
|
|
return $ numCopiesCheck'' us vs numcopies
|
2014-01-21 22:46:39 +00:00
|
|
|
approxNumCopies = fromMaybe defaultNumCopies <$> getGlobalNumCopies
|
Add and use numcopiesneeded preferred content expression.
* Add numcopiesneeded preferred content expression.
* Client, transfer, incremental backup, and archive repositories
now want to get content that does not yet have enough copies.
This means the asssistant will make copies of files that don't yet
meet the configured numcopies, even to places that would not normally want
the file.
For example, if numcopies is 4, and there are 2 client repos and
2 transfer repos, and 2 removable backup drives, the file will be sent
to both transfer repos in order to make 4 copies. Once a removable drive
get a copy of the file, it will be dropped from one transfer repo or the
other (but not both).
Another example, numcopies is 3 and there is a client that has a backup
removable drive and two small archive repos. Normally once one of the small
archives has a file, it will not be put into the other one. But, to satisfy
numcopies, the assistant will duplicate it into the other small archive
too, if the backup repo is not available to receive the file.
I notice that these examples are fairly unlikely setups .. the old behavior
was not too bad, but it's nice to finally have it really correct.
.. Almost. I have skipped checking the annex.numcopies .gitattributes
out of fear it will be too slow.
This commit was sponsored by Florian Schlegel.
2014-01-20 21:34:58 +00:00
|
|
|
|
2014-01-22 20:35:32 +00:00
|
|
|
{- Match keys that are unused.
|
|
|
|
-
|
|
|
|
- This has a nice optimisation: When a file exists,
|
|
|
|
- its key is obviously not unused.
|
|
|
|
-}
|
2014-03-29 18:43:34 +00:00
|
|
|
limitUnused :: MatchFiles Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitUnused = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const go
|
2020-09-24 20:08:47 +00:00
|
|
|
, matchNeedsFileName = True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "unused"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
|
|
|
where
|
2024-08-23 20:35:12 +00:00
|
|
|
go (MatchingFile _) = return False
|
|
|
|
go (MatchingInfo p) = maybe (pure False) isunused (providedKey p)
|
|
|
|
go (MatchingUserInfo p) = do
|
2020-09-28 16:06:10 +00:00
|
|
|
k <- getUserInfo (userProvidedKey p)
|
|
|
|
isunused k
|
|
|
|
|
|
|
|
isunused k = S.member k <$> unusedKeys
|
2014-01-22 20:35:32 +00:00
|
|
|
|
2022-12-20 19:42:34 +00:00
|
|
|
{- Adds a limit that matches anything. -}
|
|
|
|
addAnything :: Annex ()
|
|
|
|
addAnything = addLimit (Right limitAnything)
|
|
|
|
|
2016-02-02 19:18:17 +00:00
|
|
|
{- Limit that matches any version of any file or key. -}
|
2015-06-16 21:03:34 +00:00
|
|
|
limitAnything :: MatchFiles Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitAnything = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = \_ _ _ -> return True
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "anything"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2015-06-16 21:03:34 +00:00
|
|
|
|
2022-12-20 19:42:34 +00:00
|
|
|
{- Adds a limit that never matches. -}
|
|
|
|
addNothing :: Annex ()
|
|
|
|
addNothing = addLimit (Right limitNothing)
|
|
|
|
|
2016-02-02 19:18:17 +00:00
|
|
|
{- Limit that never matches. -}
|
|
|
|
limitNothing :: MatchFiles Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitNothing = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = \_ _ _ -> return False
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "nothing"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2016-02-02 19:18:17 +00:00
|
|
|
|
2012-10-08 19:18:58 +00:00
|
|
|
{- Adds a limit to skip files not believed to be present in all
|
|
|
|
- repositories in the specified group. -}
|
2012-10-10 16:59:45 +00:00
|
|
|
addInAllGroup :: String -> Annex ()
|
2015-12-04 18:57:28 +00:00
|
|
|
addInAllGroup groupname = addLimit $ limitInAllGroup groupMap groupname
|
|
|
|
|
|
|
|
limitInAllGroup :: Annex GroupMap -> MkLimit Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitInAllGroup getgroupmap groupname = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ \notpresent mi -> do
|
2020-09-24 17:55:19 +00:00
|
|
|
m <- getgroupmap
|
|
|
|
let want = fromMaybe S.empty $ M.lookup (toGroup groupname) $ uuidsByGroup m
|
|
|
|
if S.null want
|
|
|
|
then return True
|
|
|
|
-- optimisation: Check if a wanted uuid is notpresent.
|
|
|
|
else if not (S.null (S.intersection want notpresent))
|
|
|
|
then return False
|
|
|
|
else checkKey (check want) mi
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = True
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "inallgroup" =? groupname
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2015-12-04 18:57:28 +00:00
|
|
|
where
|
|
|
|
check want key = do
|
|
|
|
present <- S.fromList <$> Remote.keyLocations key
|
|
|
|
return $ S.null $ want `S.difference` present
|
2012-10-08 19:18:58 +00:00
|
|
|
|
2023-08-07 17:05:11 +00:00
|
|
|
{- Skip files unless they are present in at least one repository that is in
|
|
|
|
- the specified group, and are not present in any repositories that are not
|
|
|
|
- in the specified group. -}
|
2023-07-31 18:43:58 +00:00
|
|
|
addOnlyInGroup :: String -> Annex ()
|
|
|
|
addOnlyInGroup groupname = addLimit $ limitOnlyInGroup groupMap groupname
|
|
|
|
|
|
|
|
limitOnlyInGroup :: Annex GroupMap -> MkLimit Annex
|
|
|
|
limitOnlyInGroup getgroupmap groupname = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ \notpresent mi -> do
|
2023-07-31 18:43:58 +00:00
|
|
|
m <- getgroupmap
|
|
|
|
let want = fromMaybe S.empty $ M.lookup (toGroup groupname) $ uuidsByGroup m
|
|
|
|
if S.null want
|
|
|
|
then return False
|
|
|
|
else checkKey (check notpresent want) mi
|
|
|
|
, matchNeedsFileName = False
|
|
|
|
, matchNeedsFileContent = False
|
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = True
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2024-09-03 16:38:59 +00:00
|
|
|
, matchDesc = "onlyingroup" =? groupname
|
2023-07-31 18:43:58 +00:00
|
|
|
}
|
|
|
|
where
|
|
|
|
check notpresent want key = do
|
|
|
|
locs <- S.fromList <$> Remote.keyLocations key
|
|
|
|
let present = locs `S.difference` notpresent
|
2023-08-07 17:05:11 +00:00
|
|
|
return $ not (S.null $ present `S.intersection` want)
|
|
|
|
&& S.null (S.filter (`S.notMember` want) present)
|
2023-07-31 18:43:58 +00:00
|
|
|
|
2024-08-09 18:16:09 +00:00
|
|
|
limitBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
|
|
|
limitBalanced mu getgroupmap groupname = do
|
2024-08-21 19:01:54 +00:00
|
|
|
fullybalanced <- limitFullyBalanced' "balanced" mu getgroupmap groupname
|
|
|
|
limitBalanced' "balanced" fullybalanced mu groupname
|
|
|
|
|
|
|
|
limitBalanced' :: String -> MatchFiles Annex -> Maybe UUID -> MkLimit Annex
|
|
|
|
limitBalanced' termname fullybalanced mu groupname = do
|
2024-08-09 18:16:09 +00:00
|
|
|
copies <- limitCopies $ if ':' `elem` groupname
|
|
|
|
then groupname
|
|
|
|
else groupname ++ ":1"
|
|
|
|
let present = limitPresent mu
|
|
|
|
Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = \lu a i ->
|
2024-08-09 18:16:09 +00:00
|
|
|
ifM (Annex.getRead Annex.rebalance)
|
2024-08-23 20:35:12 +00:00
|
|
|
( matchAction fullybalanced lu a i
|
|
|
|
, matchAction present lu a i <||>
|
|
|
|
((not <$> matchAction copies lu a i)
|
|
|
|
<&&> matchAction fullybalanced lu a i
|
2024-08-09 18:16:09 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
, matchNeedsFileName =
|
|
|
|
matchNeedsFileName present ||
|
|
|
|
matchNeedsFileName fullybalanced ||
|
|
|
|
matchNeedsFileName copies
|
|
|
|
, matchNeedsFileContent =
|
|
|
|
matchNeedsFileContent present ||
|
|
|
|
matchNeedsFileContent fullybalanced ||
|
|
|
|
matchNeedsFileContent copies
|
|
|
|
, matchNeedsKey =
|
|
|
|
matchNeedsKey present ||
|
|
|
|
matchNeedsKey fullybalanced ||
|
|
|
|
matchNeedsKey copies
|
|
|
|
, matchNeedsLocationLog =
|
|
|
|
matchNeedsLocationLog present ||
|
|
|
|
matchNeedsLocationLog fullybalanced ||
|
|
|
|
matchNeedsLocationLog copies
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = True
|
2024-08-21 19:01:54 +00:00
|
|
|
, matchDesc = termname =? groupname
|
2024-08-09 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
limitFullyBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
2024-08-21 19:01:54 +00:00
|
|
|
limitFullyBalanced = limitFullyBalanced' "fullybalanced"
|
|
|
|
|
|
|
|
limitFullyBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
2024-08-27 14:17:43 +00:00
|
|
|
limitFullyBalanced' = limitFullyBalanced'' $ \n key candidates -> do
|
2024-08-21 21:56:06 +00:00
|
|
|
maxsizes <- getMaxSizes
|
2024-08-27 14:17:43 +00:00
|
|
|
sizemap <- getLiveRepoSizes False
|
2024-08-22 11:15:55 +00:00
|
|
|
threshhold <- annexFullyBalancedThreshhold <$> Annex.getGitConfig
|
2024-08-21 21:56:06 +00:00
|
|
|
let toofull u =
|
|
|
|
case (M.lookup u maxsizes, M.lookup u sizemap) of
|
|
|
|
(Just (MaxSize maxsize), Just (RepoSize reposize)) ->
|
|
|
|
fromIntegral reposize >= fromIntegral maxsize * threshhold
|
|
|
|
_ -> False
|
|
|
|
needsizebalance <- ifM (Annex.getRead Annex.rebalance)
|
|
|
|
( return $ n > 1 &&
|
|
|
|
n > S.size candidates
|
|
|
|
- S.size (S.filter toofull candidates)
|
|
|
|
, return False
|
|
|
|
)
|
|
|
|
if needsizebalance
|
|
|
|
then filterCandidatesFullySizeBalanced maxsizes sizemap n key candidates
|
|
|
|
else do
|
|
|
|
currentlocs <- S.fromList <$> loggedLocations key
|
|
|
|
let keysize = fromMaybe 0 (fromKey keySize key)
|
|
|
|
let hasspace u = case (M.lookup u maxsizes, M.lookup u sizemap) of
|
|
|
|
(Just maxsize, Just reposize) ->
|
|
|
|
repoHasSpace keysize (u `S.member` currentlocs) reposize maxsize
|
|
|
|
_ -> True
|
|
|
|
return $ S.filter hasspace candidates
|
2024-08-21 19:01:54 +00:00
|
|
|
|
|
|
|
repoHasSpace :: Integer -> Bool -> RepoSize -> MaxSize -> Bool
|
|
|
|
repoHasSpace keysize inrepo (RepoSize reposize) (MaxSize maxsize)
|
|
|
|
| inrepo =
|
|
|
|
reposize <= maxsize
|
|
|
|
| otherwise =
|
|
|
|
reposize + keysize <= maxsize
|
|
|
|
|
|
|
|
limitFullyBalanced''
|
2024-08-27 14:17:43 +00:00
|
|
|
:: (Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
2024-08-21 19:01:54 +00:00
|
|
|
-> String
|
|
|
|
-> Maybe UUID
|
|
|
|
-> Annex GroupMap
|
|
|
|
-> MkLimit Annex
|
|
|
|
limitFullyBalanced'' filtercandidates termname mu getgroupmap want =
|
2024-08-20 17:50:47 +00:00
|
|
|
case splitc ':' want of
|
|
|
|
[g] -> go g 1
|
|
|
|
[g, n] -> maybe
|
2024-08-21 19:01:54 +00:00
|
|
|
(Left $ "bad number for " ++ termname)
|
2024-08-20 17:50:47 +00:00
|
|
|
(go g)
|
|
|
|
(readish n)
|
2024-08-21 19:01:54 +00:00
|
|
|
_ -> Left $ "bad value for " ++ termname
|
2024-08-20 17:50:47 +00:00
|
|
|
where
|
2024-08-21 19:01:54 +00:00
|
|
|
go s n = limitFullyBalanced''' filtercandidates termname mu
|
|
|
|
getgroupmap (toGroup s) n want
|
2024-08-20 17:50:47 +00:00
|
|
|
|
2024-08-21 19:01:54 +00:00
|
|
|
limitFullyBalanced'''
|
2024-08-27 14:17:43 +00:00
|
|
|
:: (Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
2024-08-21 19:01:54 +00:00
|
|
|
-> String
|
|
|
|
-> Maybe UUID
|
|
|
|
-> Annex GroupMap
|
|
|
|
-> Group
|
|
|
|
-> Int
|
|
|
|
-> MkLimit Annex
|
|
|
|
limitFullyBalanced''' filtercandidates termname mu getgroupmap g n want = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = \lu -> const $ checkKey $ \key -> do
|
2024-08-10 20:32:54 +00:00
|
|
|
gm <- getgroupmap
|
|
|
|
let groupmembers = fromMaybe S.empty $
|
|
|
|
M.lookup g (uuidsByGroup gm)
|
2024-08-27 14:17:43 +00:00
|
|
|
candidates <- filtercandidates n key groupmembers
|
2024-08-24 15:49:58 +00:00
|
|
|
let wanted = if S.null candidates
|
2024-08-13 15:00:20 +00:00
|
|
|
then False
|
|
|
|
else case (mu, M.lookup g (balancedPickerByGroup gm)) of
|
2024-08-20 17:52:46 +00:00
|
|
|
(Just u, Just picker) ->
|
|
|
|
u `elem` picker candidates key n
|
2024-08-13 15:00:20 +00:00
|
|
|
_ -> False
|
2024-08-24 15:49:58 +00:00
|
|
|
when wanted $
|
2024-08-24 17:07:05 +00:00
|
|
|
needLiveUpdate lu
|
2024-08-24 15:49:58 +00:00
|
|
|
return wanted
|
2024-08-09 18:16:09 +00:00
|
|
|
, matchNeedsFileName = False
|
|
|
|
, matchNeedsFileContent = False
|
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = True
|
2024-08-21 19:01:54 +00:00
|
|
|
, matchDesc = termname =? want
|
2024-08-09 18:16:09 +00:00
|
|
|
}
|
|
|
|
|
2024-08-21 19:01:54 +00:00
|
|
|
limitSizeBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
|
|
|
limitSizeBalanced mu getgroupmap groupname = do
|
|
|
|
fullysizebalanced <- limitFullySizeBalanced' "sizebalanced" mu getgroupmap groupname
|
|
|
|
limitBalanced' "sizebalanced" fullysizebalanced mu groupname
|
|
|
|
|
|
|
|
limitFullySizeBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
|
|
|
limitFullySizeBalanced = limitFullySizeBalanced' "fullysizebalanced"
|
|
|
|
|
|
|
|
limitFullySizeBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
2024-08-27 14:17:43 +00:00
|
|
|
limitFullySizeBalanced' = limitFullyBalanced'' $ \n key candidates -> do
|
2024-08-21 21:56:06 +00:00
|
|
|
maxsizes <- getMaxSizes
|
2024-08-27 14:17:43 +00:00
|
|
|
sizemap <- getLiveRepoSizes False
|
2024-08-21 21:56:06 +00:00
|
|
|
filterCandidatesFullySizeBalanced maxsizes sizemap n key candidates
|
|
|
|
|
|
|
|
filterCandidatesFullySizeBalanced
|
|
|
|
:: M.Map UUID MaxSize
|
|
|
|
-> M.Map UUID RepoSize
|
|
|
|
-> Int
|
|
|
|
-> Key
|
|
|
|
-> S.Set UUID
|
|
|
|
-> Annex (S.Set UUID)
|
|
|
|
filterCandidatesFullySizeBalanced maxsizes sizemap n key candidates = do
|
|
|
|
currentlocs <- S.fromList <$> loggedLocations key
|
|
|
|
let keysize = fromMaybe 0 (fromKey keySize key)
|
|
|
|
let go u = case (M.lookup u maxsizes, M.lookup u sizemap, u `S.member` currentlocs) of
|
|
|
|
(Just maxsize, Just reposize, inrepo)
|
|
|
|
| repoHasSpace keysize inrepo reposize maxsize ->
|
|
|
|
proportionfree keysize inrepo u reposize maxsize
|
|
|
|
| otherwise -> Nothing
|
|
|
|
_ -> Nothing
|
|
|
|
return $ S.fromList $
|
|
|
|
map fst $ take n $ reverse $ sortOn snd $
|
|
|
|
mapMaybe go $ S.toList candidates
|
2024-08-21 19:01:54 +00:00
|
|
|
where
|
|
|
|
proportionfree keysize inrepo u (RepoSize reposize) (MaxSize maxsize)
|
|
|
|
| maxsize > 0 = Just
|
|
|
|
( u
|
|
|
|
, fromIntegral freespacesanskey / fromIntegral maxsize
|
|
|
|
:: Double
|
|
|
|
)
|
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
|
|
|
freespacesanskey = maxsize - reposize +
|
|
|
|
if inrepo then keysize else 0
|
|
|
|
|
2011-11-28 21:37:15 +00:00
|
|
|
{- Adds a limit to skip files not using a specified key-value backend. -}
|
|
|
|
addInBackend :: String -> Annex ()
|
2012-10-04 19:48:59 +00:00
|
|
|
addInBackend = addLimit . limitInBackend
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
limitInBackend :: MkLimit Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitInBackend name = Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey check
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "inbackend" =? name
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2012-10-29 02:09:09 +00:00
|
|
|
where
|
2019-11-22 20:24:04 +00:00
|
|
|
check key = pure $ fromKey keyVariety key == variety
|
2019-01-11 20:34:04 +00:00
|
|
|
variety = parseKeyVariety (encodeBS name)
|
2012-09-25 20:48:24 +00:00
|
|
|
|
2017-02-27 19:02:38 +00:00
|
|
|
{- Adds a limit to skip files not using a secure hash. -}
|
|
|
|
addSecureHash :: Annex ()
|
|
|
|
addSecureHash = addLimit $ Right limitSecureHash
|
|
|
|
|
|
|
|
limitSecureHash :: MatchFiles Annex
|
2020-09-24 17:55:19 +00:00
|
|
|
limitSecureHash = MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey isCryptographicallySecureKey
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = matchDescSimple "securehash"
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2017-02-27 19:02:38 +00:00
|
|
|
|
2012-10-08 17:39:18 +00:00
|
|
|
{- Adds a limit to skip files that are too large or too small -}
|
2020-10-19 19:36:18 +00:00
|
|
|
addLargerThan :: LimitBy -> String -> Annex ()
|
2023-07-25 20:11:06 +00:00
|
|
|
addLargerThan lb = addLimit . limitSize lb "smallerthan" (>)
|
2012-10-08 17:39:18 +00:00
|
|
|
|
2020-10-19 19:36:18 +00:00
|
|
|
addSmallerThan :: LimitBy -> String -> Annex ()
|
2023-07-25 20:11:06 +00:00
|
|
|
addSmallerThan lb = addLimit . limitSize lb "smallerthan" (<)
|
2012-10-08 17:39:18 +00:00
|
|
|
|
2023-07-25 20:11:06 +00:00
|
|
|
limitSize :: LimitBy -> String -> (Maybe Integer -> Maybe Integer -> Bool) -> MkLimit Annex
|
|
|
|
limitSize lb desc vs s = case readSize dataUnits s of
|
2012-10-08 17:39:18 +00:00
|
|
|
Nothing -> Left "bad size"
|
2020-09-24 17:55:19 +00:00
|
|
|
Just sz -> Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ go sz
|
2020-09-24 20:08:47 +00:00
|
|
|
, matchNeedsFileName = case lb of
|
|
|
|
LimitAnnexFiles -> False
|
|
|
|
LimitDiskFiles -> True
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = desc =? s
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2012-10-29 02:09:09 +00:00
|
|
|
where
|
2019-09-30 21:12:47 +00:00
|
|
|
go sz _ (MatchingFile fi) = case lb of
|
2021-03-01 20:34:40 +00:00
|
|
|
LimitAnnexFiles -> lookupFileKey fi >>= \case
|
|
|
|
Just key -> checkkey sz key
|
|
|
|
Nothing -> return False
|
|
|
|
LimitDiskFiles -> do
|
|
|
|
filesize <- liftIO $ catchMaybeIO $ getFileSize (contentFile fi)
|
|
|
|
return $ filesize `vs` Just sz
|
2021-03-02 16:47:23 +00:00
|
|
|
go sz _ (MatchingInfo p) = case providedFileSize p of
|
|
|
|
Just sz' -> pure (Just sz' `vs` Just sz)
|
|
|
|
Nothing -> maybe (pure False) (checkkey sz) (providedKey p)
|
2020-09-28 16:06:10 +00:00
|
|
|
go sz _ (MatchingUserInfo p) =
|
|
|
|
getUserInfo (userProvidedFileSize p)
|
2019-04-30 15:58:06 +00:00
|
|
|
>>= \sz' -> return (Just sz' `vs` Just sz)
|
2019-11-22 20:24:04 +00:00
|
|
|
checkkey sz key = return $ fromKey keySize key `vs` Just sz
|
2012-10-08 17:39:18 +00:00
|
|
|
|
2014-02-13 06:24:30 +00:00
|
|
|
addMetaData :: String -> Annex ()
|
|
|
|
addMetaData = addLimit . limitMetaData
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
limitMetaData :: MkLimit Annex
|
2016-02-27 14:55:02 +00:00
|
|
|
limitMetaData s = case parseMetaDataMatcher s of
|
2014-02-13 06:24:30 +00:00
|
|
|
Left e -> Left e
|
2020-09-24 17:55:19 +00:00
|
|
|
Right (f, matching) -> Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey (check f matching)
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = True
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "metadata" =? s
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2014-02-13 06:24:30 +00:00
|
|
|
where
|
2016-02-27 14:55:02 +00:00
|
|
|
check f matching k = not . S.null
|
|
|
|
. S.filter matching
|
2014-02-21 22:34:34 +00:00
|
|
|
. metaDataValues f <$> getCurrentMetaData k
|
2014-02-13 06:24:30 +00:00
|
|
|
|
2018-08-01 19:20:18 +00:00
|
|
|
addAccessedWithin :: Duration -> Annex ()
|
|
|
|
addAccessedWithin duration = do
|
|
|
|
now <- liftIO getPOSIXTime
|
2020-09-24 17:55:19 +00:00
|
|
|
addLimit $ Right $ MatchFiles
|
2024-08-23 20:35:12 +00:00
|
|
|
{ matchAction = const $ const $ checkKey $ check now
|
2020-09-24 19:12:09 +00:00
|
|
|
, matchNeedsFileName = False
|
2020-09-24 17:55:19 +00:00
|
|
|
, matchNeedsFileContent = False
|
2020-09-24 21:59:05 +00:00
|
|
|
, matchNeedsKey = False
|
|
|
|
, matchNeedsLocationLog = False
|
2024-08-28 14:52:34 +00:00
|
|
|
, matchNeedsLiveRepoSize = False
|
2023-07-25 20:11:06 +00:00
|
|
|
, matchDesc = "accessedwithin" =? fromDuration duration
|
2020-09-24 17:55:19 +00:00
|
|
|
}
|
2018-08-01 19:20:18 +00:00
|
|
|
where
|
|
|
|
check now k = inAnnexCheck k $ \f ->
|
|
|
|
liftIO $ catchDefaultIO False $ do
|
2022-09-05 17:44:03 +00:00
|
|
|
s <- R.getSymbolicLinkStatus f
|
2018-08-01 19:20:18 +00:00
|
|
|
let accessed = realToFrac (accessTime s)
|
|
|
|
let delta = now - accessed
|
|
|
|
return $ delta <= secs
|
|
|
|
secs = fromIntegral (durationSeconds duration)
|
|
|
|
|
2014-01-18 18:51:55 +00:00
|
|
|
lookupFileKey :: FileInfo -> Annex (Maybe Key)
|
2020-12-14 21:42:02 +00:00
|
|
|
lookupFileKey fi = case matchKey fi of
|
|
|
|
Just k -> return (Just k)
|
2021-03-01 20:34:40 +00:00
|
|
|
Nothing -> lookupKey (contentFile fi)
|
2014-01-18 18:51:55 +00:00
|
|
|
|
|
|
|
checkKey :: (Key -> Annex Bool) -> MatchInfo -> Annex Bool
|
|
|
|
checkKey a (MatchingFile fi) = lookupFileKey fi >>= maybe (return False) a
|
2020-09-28 16:06:10 +00:00
|
|
|
checkKey a (MatchingInfo p) = maybe (return False) a (providedKey p)
|
|
|
|
checkKey a (MatchingUserInfo p) = a =<< getUserInfo (userProvidedKey p)
|
2023-07-25 20:11:06 +00:00
|
|
|
|
2023-07-26 19:29:23 +00:00
|
|
|
matchDescSimple :: String -> (Bool -> Utility.Matcher.MatchDesc)
|
|
|
|
matchDescSimple s b = Utility.Matcher.MatchDesc $ s ++
|
|
|
|
if b then "[TRUE]" else "[FALSE]"
|
2023-07-25 20:11:06 +00:00
|
|
|
|
|
|
|
(=?) :: String -> String -> (Bool -> Utility.Matcher.MatchDesc)
|
2023-07-26 19:29:23 +00:00
|
|
|
k =? v = matchDescSimple (k ++ "=" ++ v)
|