annex.largefiles: Add support for mimetype=text/* etc, when git-annex is linked with libmagic.
This commit is contained in:
parent
86444fe507
commit
5127cb59cc
8 changed files with 78 additions and 11 deletions
|
@ -5,6 +5,8 @@
|
|||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Annex.FileMatcher (
|
||||
GetFileMatcher,
|
||||
checkFileMatcher,
|
||||
|
@ -28,6 +30,10 @@ import Types.Remote (RemoteConfig)
|
|||
import Annex.CheckAttr
|
||||
import Git.CheckAttr (unspecifiedAttr)
|
||||
|
||||
#ifdef WITH_MAGICMIME
|
||||
import Magic
|
||||
#endif
|
||||
|
||||
import Data.Either
|
||||
import qualified Data.Set as S
|
||||
|
||||
|
@ -119,10 +125,19 @@ preferredContentParser matchstandard matchgroupwanted getgroupmap configmap mu e
|
|||
preferreddir = fromMaybe "public" $
|
||||
M.lookup "preferreddir" =<< (`M.lookup` configmap) =<< mu
|
||||
|
||||
largeFilesParser :: String -> [ParseResult]
|
||||
largeFilesParser expr = map parse $ tokenizeMatcher expr
|
||||
where
|
||||
parse = parseToken commonTokens
|
||||
mkLargeFilesParser :: Annex (String -> [ParseResult])
|
||||
mkLargeFilesParser = do
|
||||
#ifdef WITH_MAGICMIME
|
||||
magicmime <- liftIO $ magicOpen [MagicMimeType]
|
||||
liftIO $ magicLoadDefault magicmime
|
||||
#endif
|
||||
let parse = parseToken $ commonTokens
|
||||
#ifdef WITH_MAGICMIME
|
||||
++ [ ValueToken "mimetype" (usev $ matchMagic magicmime) ]
|
||||
#else
|
||||
++ [ ValueToken "mimetype" (const $ Left "\"mimetype\" not supported; not built with MagicMime support") ]
|
||||
#endif
|
||||
return $ map parse . tokenizeMatcher
|
||||
|
||||
{- Generates a matcher for files large enough (or meeting other criteria)
|
||||
- to be added to the annex, rather than directly to git. -}
|
||||
|
@ -138,7 +153,9 @@ largeFilesMatcher = go =<< annexLargeFiles <$> Annex.getGitConfig
|
|||
then return matchAll
|
||||
else mkmatcher expr
|
||||
|
||||
mkmatcher = either badexpr return . parsedToMatcher . largeFilesParser
|
||||
mkmatcher expr = do
|
||||
parser <- mkLargeFilesParser
|
||||
either badexpr return $ parsedToMatcher $ parser expr
|
||||
badexpr e = error $ "bad annex.largefiles configuration: " ++ e
|
||||
|
||||
simply :: MatchFiles Annex -> ParseResult
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue