From 462217110db8f07463b28bb77dcbdb7c773eff49 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 23 Feb 2016 14:39:56 -0400 Subject: Avoid crashing when built with MagicMime support, but when the magic database cannot be loaded. --- Annex/FileMatcher.hs | 6 ++++-- Limit.hs | 5 +++-- debian/changelog | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Annex/FileMatcher.hs b/Annex/FileMatcher.hs index e97b80c82..5167a5e02 100644 --- a/Annex/FileMatcher.hs +++ b/Annex/FileMatcher.hs @@ -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 diff --git a/Limit.hs b/Limit.hs index 9bf5e22d9..174d4582d 100644 --- a/Limit.hs +++ b/Limit.hs @@ -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 diff --git a/debian/changelog b/debian/changelog index c1768b73e..0184c13ff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Thu, 18 Feb 2016 13:09:21 -0400 -- cgit v1.2.3