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

@ -129,8 +129,10 @@ preferredContentParser matchstandard matchgroupwanted getgroupmap configmap mu e
mkLargeFilesParser :: Annex (String -> [ParseResult])
mkLargeFilesParser = do
#ifdef WITH_MAGICMIME
magicmime <- liftIO $ magicOpen [MagicMimeType]
liftIO $ magicLoadDefault magicmime
magicmime <- liftIO $ catchMaybeIO $ do
m <- magicOpen [MagicMimeType]
liftIO $ magicLoadDefault m
return m
#endif
let parse = parseToken $ commonTokens
#ifdef WITH_MAGICMIME

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

2
debian/changelog vendored
View file

@ -9,6 +9,8 @@ git-annex (6.20160218) UNRELEASED; urgency=medium
* info: Mention when run in a dead repository.
* Linux and OSX standalone builds put the bundled gpg last in PATH,
so any system gpg will be preferred over it.
* Avoid crashing when built with MagicMime support, but when the magic
database cannot be loaded.
-- Joey Hess <id@joeyh.name> Thu, 18 Feb 2016 13:09:21 -0400