diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-02-23 14:39:56 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-02-23 14:39:56 -0400 |
commit | 462217110db8f07463b28bb77dcbdb7c773eff49 (patch) | |
tree | f2c3f31f2cae2f9ee66d63c5e5b6140c2b6f5f55 | |
parent | 23ed99f1874978fa415a55110b3291ff1381ae66 (diff) |
Avoid crashing when built with MagicMime support, but when the magic database cannot be loaded.
-rw-r--r-- | Annex/FileMatcher.hs | 6 | ||||
-rw-r--r-- | Limit.hs | 5 | ||||
-rw-r--r-- | 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 @@ -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 <id@joeyh.name> Thu, 18 Feb 2016 13:09:21 -0400 |