2013-10-28 18:50:17 +00:00
|
|
|
{- git-annex limits by wanted status
|
|
|
|
-
|
2020-09-24 21:59:05 +00:00
|
|
|
- Copyright 2012-2020 Joey Hess <id@joeyh.name>
|
2013-10-28 18:50:17 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-10-28 18:50:17 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Limit.Wanted where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-10-28 18:50:17 +00:00
|
|
|
import Annex.Wanted
|
|
|
|
import Limit
|
|
|
|
import Types.FileMatcher
|
2020-09-24 21:59:05 +00:00
|
|
|
import Logs.PreferredContent
|
2013-10-28 18:50:17 +00:00
|
|
|
|
|
|
|
addWantGet :: Annex ()
|
2020-09-24 21:59:05 +00:00
|
|
|
addWantGet = addPreferredContentLimit $
|
|
|
|
checkWant $ wantGet False Nothing
|
2013-10-28 18:50:17 +00:00
|
|
|
|
|
|
|
addWantDrop :: Annex ()
|
2020-09-24 21:59:05 +00:00
|
|
|
addWantDrop = addPreferredContentLimit $
|
fix longstanding indeterminite preferred content for duplicated file problem
* drop: When two files have the same content, and a preferred content
expression matches one but not the other, do not drop the file.
* sync --content, assistant: Fix an edge case where a file that is not
preferred content did not get dropped.
The sync --content edge case is that handleDropsFrom loaded associated files
and used them without verifying that the information from the database was
not stale.
It seemed best to avoid changing --want-drop's behavior, this way when
debugging a preferred content expression with it, the files matched will
still reflect the expression. So added a note to the --want-drop documentation,
to make clear it may not behave identically to git-annex drop --auto.
While it would be possible to introspect the preferred content
expression to see if it matches on filenames, and only look up the
associated files when it does, it's generally fairly rare for 2 files to
have the same content, and the database lookup is already avoided when
there's only 1 file, so I did not implement that further optimisation.
Note that there are still some situations where the associated files
database does not get locked files recorded in it, which will prevent
this fix from working.
Sponsored-by: Dartmouth College's Datalad project
2021-05-24 18:02:50 +00:00
|
|
|
checkWant $ \af -> wantDrop False Nothing Nothing af (Just [])
|
2020-09-24 21:59:05 +00:00
|
|
|
|
|
|
|
addPreferredContentLimit :: (MatchInfo -> Annex Bool) -> Annex ()
|
|
|
|
addPreferredContentLimit a = do
|
|
|
|
nfn <- introspectPreferredRequiredContent matchNeedsFileName Nothing
|
|
|
|
nfc <- introspectPreferredRequiredContent matchNeedsFileContent Nothing
|
|
|
|
nk <- introspectPreferredRequiredContent matchNeedsKey Nothing
|
2020-09-25 14:55:03 +00:00
|
|
|
nl <- introspectPreferredRequiredContent matchNeedsLocationLog Nothing
|
2020-09-24 21:59:05 +00:00
|
|
|
addLimit $ Right $ MatchFiles
|
|
|
|
{ matchAction = const a
|
|
|
|
, matchNeedsFileName = nfn
|
|
|
|
, matchNeedsFileContent = nfc
|
|
|
|
, matchNeedsKey = nk
|
2020-09-25 14:55:03 +00:00
|
|
|
, matchNeedsLocationLog = nl
|
2020-09-24 21:59:05 +00:00
|
|
|
}
|
2014-01-18 18:51:55 +00:00
|
|
|
|
2017-03-10 17:12:24 +00:00
|
|
|
checkWant :: (AssociatedFile -> Annex Bool) -> MatchInfo -> Annex Bool
|
2019-12-09 17:49:05 +00:00
|
|
|
checkWant a (MatchingFile fi) = a (AssociatedFile (Just $ matchFile fi))
|
2021-03-02 16:47:23 +00:00
|
|
|
checkWant a (MatchingInfo p) = a (AssociatedFile (providedFilePath p))
|
2020-09-28 16:06:10 +00:00
|
|
|
checkWant _ (MatchingUserInfo {}) = return False
|