allow matching on files whose content is not present
Anything that needs to examine the file content will fail to match, or fall back to other available information. But the intent is that the matcher be checked for matchNeedsFileContent and only be used if it does not, so the exact behavior doesn't much matter as it should never happen. The real point of this is to not need to provide a dummy content file when matching. This commit was sponsored by Martin D on Patreon.
This commit is contained in:
parent
9e676f062f
commit
00dbe35fbc
11 changed files with 40 additions and 30 deletions
|
@ -85,7 +85,7 @@ fileMatchInfo file = do
|
|||
matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
|
||||
return $ MatchingFile FileInfo
|
||||
{ matchFile = matchfile
|
||||
, currFile = file
|
||||
, contentFile = Just file
|
||||
}
|
||||
|
||||
matchAll :: FileMatcher Annex
|
||||
|
|
|
@ -452,7 +452,7 @@ importKeys remote importtreeconfig importcontent importablecontents = do
|
|||
matcher <- largematcher (fromRawFilePath f)
|
||||
let mi = MatchingFile FileInfo
|
||||
{ matchFile = f
|
||||
, currFile = toRawFilePath tmpfile
|
||||
, contentFile = Just (toRawFilePath tmpfile)
|
||||
}
|
||||
islargefile <- checkMatcher' matcher mi mempty
|
||||
if islargefile
|
||||
|
|
|
@ -366,7 +366,7 @@ addAnnexedFile ci matcher file key mtmp = ifM (addUnlocked matcher mi)
|
|||
where
|
||||
mi = case mtmp of
|
||||
Just tmp -> MatchingFile $ FileInfo
|
||||
{ currFile = toRawFilePath tmp
|
||||
{ contentFile = Just (toRawFilePath tmp)
|
||||
, matchFile = toRawFilePath file
|
||||
}
|
||||
-- Provide as much info as we can without access to the
|
||||
|
|
|
@ -131,7 +131,7 @@ batchFilesMatching fmt a = do
|
|||
matcher <- getMatcher
|
||||
go $ \si f ->
|
||||
let f' = toRawFilePath f
|
||||
in ifM (matcher $ MatchingFile $ FileInfo f' f')
|
||||
in ifM (matcher $ MatchingFile $ FileInfo (Just f') f')
|
||||
( a (si, f')
|
||||
, return Nothing
|
||||
)
|
||||
|
|
|
@ -106,7 +106,7 @@ withPathContents a params = do
|
|||
, return [(p, takeFileName p)]
|
||||
)
|
||||
checkmatch matcher (f, relf) = matcher $ MatchingFile $ FileInfo
|
||||
{ currFile = toRawFilePath f
|
||||
{ contentFile = Just (toRawFilePath f)
|
||||
, matchFile = toRawFilePath relf
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ seekFiltered prefilter a listfs = do
|
|||
where
|
||||
process matcher v@(_si, f) =
|
||||
whenM (prefilter v) $
|
||||
whenM (matcher $ MatchingFile $ FileInfo f f) $
|
||||
whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $
|
||||
a v
|
||||
|
||||
data MatcherInfo = MatcherInfo
|
||||
|
@ -358,7 +358,7 @@ seekFilteredKeys seeker listfs = do
|
|||
-- checked later, to avoid a slow lookup here.
|
||||
(not ((matcherNeedsKey mi || matcherNeedsLocationLog mi)
|
||||
&& not (matcherNeedsFileName mi)))
|
||||
(MatchingFile $ FileInfo f f)
|
||||
(MatchingFile $ FileInfo (Just f) f)
|
||||
(liftIO $ ofeeder ((si, f), sha))
|
||||
|
||||
keyaction f mi content a =
|
||||
|
|
|
@ -176,7 +176,7 @@ start o si file addunlockedmatcher = do
|
|||
perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
|
||||
perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
|
||||
lockingfile <- not <$> addUnlocked addunlockedmatcher
|
||||
(MatchingFile (FileInfo file file))
|
||||
(MatchingFile (FileInfo (Just file) file))
|
||||
let cfg = LockDownConfig
|
||||
{ lockingFile = lockingfile
|
||||
, hardlinkFileTmpDir = Just tmpdir
|
||||
|
|
|
@ -223,7 +223,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
|
|||
stop
|
||||
lockdown a = do
|
||||
let mi = MatchingFile $ FileInfo
|
||||
{ currFile = toRawFilePath srcfile
|
||||
{ contentFile = Just (toRawFilePath srcfile)
|
||||
, matchFile = toRawFilePath destfile
|
||||
}
|
||||
lockingfile <- not <$> addUnlocked addunlockedmatcher mi
|
||||
|
|
|
@ -568,7 +568,7 @@ getDirStatInfo o dir = do
|
|||
where
|
||||
initial = (emptyKeyInfo, emptyKeyInfo, emptyNumCopiesStats, M.empty)
|
||||
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats, repodata) =
|
||||
ifM (matcher $ MatchingFile $ FileInfo file file)
|
||||
ifM (matcher $ MatchingFile $ FileInfo (Just file) file)
|
||||
( do
|
||||
!presentdata' <- ifM (inAnnex key)
|
||||
( return $ addKey key presentdata
|
||||
|
|
|
@ -133,7 +133,7 @@ send ups fs = do
|
|||
(fs', cleanup) <- seekHelper id ww LsFiles.inRepo
|
||||
=<< workTreeItems ww fs
|
||||
matcher <- Limit.getMatcher
|
||||
let addlist f o = whenM (matcher $ MatchingFile $ FileInfo f f) $
|
||||
let addlist f o = whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $
|
||||
liftIO $ hPutStrLn h o
|
||||
forM_ fs' $ \(_, f) -> do
|
||||
mk <- lookupKey f
|
||||
|
|
43
Limit.hs
43
Limit.hs
|
@ -155,9 +155,11 @@ matchMagic _limitname querymagic selectprovidedinfo (Just magic) glob =
|
|||
where
|
||||
cglob = compileGlob glob CaseSensative -- memoized
|
||||
go (MatchingKey _ _) = pure False
|
||||
go (MatchingFile fi) = catchBoolIO $
|
||||
maybe False (matchGlob cglob)
|
||||
<$> querymagic magic (fromRawFilePath (currFile fi))
|
||||
go (MatchingFile fi) = case contentFile fi of
|
||||
Just f -> catchBoolIO $
|
||||
maybe False (matchGlob cglob)
|
||||
<$> querymagic magic (fromRawFilePath f)
|
||||
Nothing -> return False
|
||||
go (MatchingInfo p) =
|
||||
matchGlob cglob <$> getInfo (selectprovidedinfo p)
|
||||
matchMagic limitname _ _ Nothing _ =
|
||||
|
@ -184,12 +186,14 @@ addLocked = addLimit $ Right $ MatchFiles
|
|||
matchLockStatus :: Bool -> MatchInfo -> Annex Bool
|
||||
matchLockStatus _ (MatchingKey _ _) = pure False
|
||||
matchLockStatus _ (MatchingInfo _) = pure False
|
||||
matchLockStatus wantlocked (MatchingFile fi) = liftIO $ do
|
||||
islocked <- isPointerFile (currFile fi) >>= \case
|
||||
Just _key -> return False
|
||||
Nothing -> isSymbolicLink
|
||||
<$> getSymbolicLinkStatus (fromRawFilePath (currFile fi))
|
||||
return (islocked == wantlocked)
|
||||
matchLockStatus wantlocked (MatchingFile fi) = case contentFile fi of
|
||||
Just f -> liftIO $ do
|
||||
islocked <- isPointerFile f >>= \case
|
||||
Just _key -> return False
|
||||
Nothing -> isSymbolicLink
|
||||
<$> getSymbolicLinkStatus (fromRawFilePath f)
|
||||
return (islocked == wantlocked)
|
||||
Nothing -> return False
|
||||
|
||||
{- Adds a limit to skip files not believed to be present
|
||||
- in a specfied repository. Optionally on a prior date. -}
|
||||
|
@ -436,17 +440,20 @@ limitSize lb vs s = case readSize dataUnits s of
|
|||
}
|
||||
where
|
||||
go sz _ (MatchingFile fi) = case lb of
|
||||
LimitAnnexFiles -> lookupFileKey fi >>= \case
|
||||
Just key -> checkkey sz key
|
||||
Nothing -> return False
|
||||
LimitDiskFiles -> do
|
||||
filesize <- liftIO $ catchMaybeIO $
|
||||
getFileSize (fromRawFilePath (currFile fi))
|
||||
return $ filesize `vs` Just sz
|
||||
LimitAnnexFiles -> goannexed sz fi
|
||||
LimitDiskFiles -> case contentFile fi of
|
||||
Just f -> do
|
||||
filesize <- liftIO $ catchMaybeIO $
|
||||
getFileSize (fromRawFilePath f)
|
||||
return $ filesize `vs` Just sz
|
||||
Nothing -> goannexed sz fi
|
||||
go sz _ (MatchingKey key _) = checkkey sz key
|
||||
go sz _ (MatchingInfo p) =
|
||||
getInfo (providedFileSize p)
|
||||
>>= \sz' -> return (Just sz' `vs` Just sz)
|
||||
goannexed sz fi = lookupFileKey fi >>= \case
|
||||
Just key -> checkkey sz key
|
||||
Nothing -> return False
|
||||
checkkey sz key = return $ fromKey keySize key `vs` Just sz
|
||||
|
||||
addMetaData :: String -> Annex ()
|
||||
|
@ -506,7 +513,9 @@ addAccessedWithin duration = do
|
|||
secs = fromIntegral (durationSeconds duration)
|
||||
|
||||
lookupFileKey :: FileInfo -> Annex (Maybe Key)
|
||||
lookupFileKey = lookupKey . currFile
|
||||
lookupFileKey fi = case contentFile fi of
|
||||
Just f -> lookupKey f
|
||||
Nothing -> return Nothing
|
||||
|
||||
checkKey :: (Key -> Annex Bool) -> MatchInfo -> Annex Bool
|
||||
checkKey a (MatchingFile fi) = lookupFileKey fi >>= maybe (return False) a
|
||||
|
|
|
@ -25,8 +25,9 @@ data MatchInfo
|
|||
| MatchingInfo ProvidedInfo
|
||||
|
||||
data FileInfo = FileInfo
|
||||
{ currFile :: RawFilePath
|
||||
-- ^ current path to the file, for operations that examine it
|
||||
{ contentFile :: Maybe RawFilePath
|
||||
-- ^ path to a file containing the content, for operations
|
||||
-- that examine it
|
||||
, matchFile :: RawFilePath
|
||||
-- ^ filepath to match on; may be relative to top of repo or cwd
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue