add key to FileInfo

MatchingKey is not the thing to use when matching on actual worktreee
files.

Fix reversion in 8.20201116 that made include= and exclude= in
preferred/required content expressions match a path relative to the current
directory, rather than the path from the top of the repository.
This commit is contained in:
Joey Hess 2020-12-14 17:42:02 -04:00
parent 205a837e8a
commit 01527b21d8
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 48 additions and 13 deletions

View file

@ -72,7 +72,8 @@ checkMatcher :: FileMatcher Annex -> Maybe Key -> AssociatedFile -> AssumeNotPre
checkMatcher matcher mkey afile notpresent notconfigured d checkMatcher matcher mkey afile notpresent notconfigured d
| isEmpty matcher = notconfigured | isEmpty matcher = notconfigured
| otherwise = case (mkey, afile) of | otherwise = case (mkey, afile) of
(Nothing, AssociatedFile (Just file)) -> go =<< fileMatchInfo file (mkey, AssociatedFile (Just file)) ->
go =<< fileMatchInfo file mkey
(Just key, _) -> go (MatchingKey key afile) (Just key, _) -> go (MatchingKey key afile)
_ -> d _ -> d
where where
@ -82,12 +83,13 @@ checkMatcher' :: FileMatcher Annex -> MatchInfo -> AssumeNotPresent -> Annex Boo
checkMatcher' matcher mi notpresent = checkMatcher' matcher mi notpresent =
matchMrun matcher $ \o -> matchAction o notpresent mi matchMrun matcher $ \o -> matchAction o notpresent mi
fileMatchInfo :: RawFilePath -> Annex MatchInfo fileMatchInfo :: RawFilePath -> Maybe Key -> Annex MatchInfo
fileMatchInfo file = do fileMatchInfo file mkey = do
matchfile <- getTopFilePath <$> inRepo (toTopFilePath file) matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
return $ MatchingFile FileInfo return $ MatchingFile FileInfo
{ matchFile = matchfile { matchFile = matchfile
, contentFile = Just file , contentFile = Just file
, matchKey = mkey
} }
matchAll :: FileMatcher Annex matchAll :: FileMatcher Annex

View file

@ -531,6 +531,7 @@ importKeys remote importtreeconfig importcontent importablecontents = do
let mi = MatchingFile FileInfo let mi = MatchingFile FileInfo
{ matchFile = f { matchFile = f
, contentFile = Just tmpfile , contentFile = Just tmpfile
, matchKey = Nothing
} }
islargefile <- checkMatcher' matcher mi mempty islargefile <- checkMatcher' matcher mi mempty
if islargefile if islargefile

View file

@ -17,6 +17,9 @@ git-annex (8.20201128) UNRELEASED; urgency=medium
* Avoid autoinit when a repo does not have annex.version or annex.uuid * Avoid autoinit when a repo does not have annex.version or annex.uuid
set, but has a git-annex objects directory, suggesting it was used set, but has a git-annex objects directory, suggesting it was used
by git-annex before. by git-annex before.
* Fix reversion in 8.20201116 that made include= and exclude= in
preferred/required content expressions match a path relative to the
current directory, rather than the path from the top of the repository.
-- Joey Hess <id@joeyh.name> Mon, 30 Nov 2020 12:55:49 -0400 -- Joey Hess <id@joeyh.name> Mon, 30 Nov 2020 12:55:49 -0400

View file

@ -131,7 +131,7 @@ batchFilesMatching fmt a = do
matcher <- getMatcher matcher <- getMatcher
go $ \si f -> go $ \si f ->
let f' = toRawFilePath f let f' = toRawFilePath f
in ifM (matcher $ MatchingFile $ FileInfo (Just f') f') in ifM (matcher $ MatchingFile $ FileInfo (Just f') f' Nothing)
( a (si, f') ( a (si, f')
, return Nothing , return Nothing
) )

View file

@ -115,6 +115,7 @@ withPathContents a params = do
checkmatch matcher (f, relf) = matcher $ MatchingFile $ FileInfo checkmatch matcher (f, relf) = matcher $ MatchingFile $ FileInfo
{ contentFile = Just f { contentFile = Just f
, matchFile = relf , matchFile = relf
, matchKey = Nothing
} }
withWords :: ([String] -> CommandSeek) -> CmdParams -> CommandSeek withWords :: ([String] -> CommandSeek) -> CmdParams -> CommandSeek
@ -287,7 +288,7 @@ seekFiltered prefilter a listfs = do
where where
process matcher v@(_si, f) = process matcher v@(_si, f) =
whenM (prefilter v) $ whenM (prefilter v) $
whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $ whenM (matcher $ MatchingFile $ FileInfo (Just f) f Nothing) $
a v a v
data MatcherInfo = MatcherInfo data MatcherInfo = MatcherInfo
@ -365,7 +366,7 @@ seekFilteredKeys seeker listfs = do
-- checked later, to avoid a slow lookup here. -- checked later, to avoid a slow lookup here.
(not ((matcherNeedsKey mi || matcherNeedsLocationLog mi) (not ((matcherNeedsKey mi || matcherNeedsLocationLog mi)
&& not (matcherNeedsFileName mi))) && not (matcherNeedsFileName mi)))
(MatchingFile $ FileInfo (Just f) f) (MatchingFile $ FileInfo (Just f) f Nothing)
(liftIO $ ofeeder ((si, f), sha)) (liftIO $ ofeeder ((si, f), sha))
keyaction f mi content a = keyaction f mi content a =

View file

@ -184,7 +184,7 @@ start o si file addunlockedmatcher = do
perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
lockingfile <- not <$> addUnlocked addunlockedmatcher lockingfile <- not <$> addUnlocked addunlockedmatcher
(MatchingFile (FileInfo (Just file) file)) (MatchingFile (FileInfo (Just file) file Nothing))
let cfg = LockDownConfig let cfg = LockDownConfig
{ lockingFile = lockingfile { lockingFile = lockingfile
, hardlinkFileTmpDir = Just tmpdir , hardlinkFileTmpDir = Just tmpdir

View file

@ -241,6 +241,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
let mi = MatchingFile $ FileInfo let mi = MatchingFile $ FileInfo
{ contentFile = Just srcfile { contentFile = Just srcfile
, matchFile = destfile , matchFile = destfile
, matchKey = Nothing
} }
lockingfile <- not <$> addUnlocked addunlockedmatcher mi lockingfile <- not <$> addUnlocked addunlockedmatcher mi
-- Minimal lock down with no hard linking so nothing -- Minimal lock down with no hard linking so nothing

View file

@ -569,7 +569,7 @@ getDirStatInfo o dir = do
where where
initial = (emptyKeyInfo, emptyKeyInfo, emptyNumCopiesStats, M.empty) initial = (emptyKeyInfo, emptyKeyInfo, emptyNumCopiesStats, M.empty)
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats, repodata) = update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats, repodata) =
ifM (matcher $ MatchingFile $ FileInfo (Just file) file) ifM (matcher $ MatchingFile $ FileInfo (Just file) file (Just key))
( do ( do
!presentdata' <- ifM (inAnnex key) !presentdata' <- ifM (inAnnex key)
( return $ addKey key presentdata ( return $ addKey key presentdata

View file

@ -135,7 +135,7 @@ send ups fs = do
(fs', cleanup) <- seekHelper id ww LsFiles.inRepo (fs', cleanup) <- seekHelper id ww LsFiles.inRepo
=<< workTreeItems ww fs =<< workTreeItems ww fs
matcher <- Limit.getMatcher matcher <- Limit.getMatcher
let addlist f o = whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $ let addlist f o = whenM (matcher $ MatchingFile $ FileInfo (Just f) f Nothing) $
liftIO $ hPutStrLn h o liftIO $ hPutStrLn h o
forM_ fs' $ \(_, f) -> do forM_ fs' $ \(_, f) -> do
mk <- lookupKey f mk <- lookupKey f

View file

@ -535,9 +535,11 @@ addAccessedWithin duration = do
secs = fromIntegral (durationSeconds duration) secs = fromIntegral (durationSeconds duration)
lookupFileKey :: FileInfo -> Annex (Maybe Key) lookupFileKey :: FileInfo -> Annex (Maybe Key)
lookupFileKey fi = case contentFile fi of lookupFileKey fi = case matchKey fi of
Just f -> lookupKey f Just k -> return (Just k)
Nothing -> return Nothing Nothing -> case contentFile fi of
Just f -> lookupKey f
Nothing -> return Nothing
checkKey :: (Key -> Annex Bool) -> MatchInfo -> Annex Bool checkKey :: (Key -> Annex Bool) -> MatchInfo -> Annex Bool
checkKey a (MatchingFile fi) = lookupFileKey fi >>= maybe (return False) a checkKey a (MatchingFile fi) = lookupFileKey fi >>= maybe (return False) a

View file

@ -18,10 +18,13 @@ import Control.Monad.IO.Class
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.Set as S import qualified Data.Set as S
-- Information about a file or a key that can be matched on. -- Information about a file and/or a key that can be matched on.
data MatchInfo data MatchInfo
= MatchingFile FileInfo = MatchingFile FileInfo
| MatchingKey Key AssociatedFile | MatchingKey Key AssociatedFile
-- ^ This is used when operating on a file that may be in another
-- branch. The AssociatedFile is the filename, but it should not be
-- accessed from disk when matching.
| MatchingInfo ProvidedInfo | MatchingInfo ProvidedInfo
| MatchingUserInfo UserProvidedInfo | MatchingUserInfo UserProvidedInfo
@ -33,6 +36,8 @@ data FileInfo = FileInfo
-- ^ filepath to match on; may be relative to top of repo or cwd, -- ^ filepath to match on; may be relative to top of repo or cwd,
-- depending on how globs in preferred content expressions -- depending on how globs in preferred content expressions
-- are intended to be matched -- are intended to be matched
, matchKey :: Maybe Key
-- ^ provided if a key is already known
} }
data ProvidedInfo = ProvidedInfo data ProvidedInfo = ProvidedInfo

View file

@ -194,3 +194,5 @@ Yes, so far it has worked nicely archiving (and describing via git-annex metadat
orderly fashion. orderly fashion.
[[!meta author=jkniiv]] [[!meta author=jkniiv]]
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,18 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2020-12-14T19:36:20Z"
content="""
Looks like it was caused by [[!commit d032b0885d80d12c00fa8813e88deab1631eef8a]] which made MatchingKey be used
rather than MatchingFile. Which oops, mean the filename is left relative rather
than being made into a path from the top of the repo.
Fixed that and your test case works. I do think this would be a better
expression for you to use though:
(include=*.mrimg and exclude=*/arkistoidut/* and exclude=arkistoidut/*)
Or maybe just exclude=arkistoidut/* rather than both, depending on if you
want to support subdirectories of subdirectories with that name, or only
the single subdirectory in the top of your repo.
"""]]