Avoid crashing when built with MagicMime support, but when the magic database cannot be loaded.

This commit is contained in:
Joey Hess 2016-02-23 14:39:56 -04:00
parent 2bf90c7b56
commit a5bf674bec
Failed to extract signature
3 changed files with 9 additions and 4 deletions

View file

@ -97,14 +97,15 @@ matchGlobFile glob = go
go (MatchingInfo af _ _ _) = matchGlob cglob <$> getInfo af
#ifdef WITH_MAGICMIME
matchMagic :: Magic -> MkLimit Annex
matchMagic magic glob = Right $ const go
matchMagic :: Maybe Magic -> MkLimit Annex
matchMagic (Just magic) glob = Right $ const go
where
cglob = compileGlob glob CaseSensative -- memoized
go (MatchingKey _) = pure False
go (MatchingFile fi) = liftIO $ catchBoolIO $
matchGlob cglob <$> magicFile magic (matchFile fi)
go (MatchingInfo _ _ _ mimeval) = matchGlob cglob <$> getInfo mimeval
matchMagic Nothing _ = Left "unable to load magic database; \"mimetype\" cannot be used"
#endif
{- Adds a limit to skip files not believed to be present