git-annex/CmdLine/GitAnnexShell/Fields.hs

43 lines
962 B
Haskell
Raw Normal View History

2014-01-26 20:37:27 +00:00
{- git-annex-shell fields
-
- Copyright 2012 Joey Hess <id@joeyh.name>
2014-01-26 20:37:27 +00:00
-
- Licensed under the GNU AGPL version 3 or higher.
2014-01-26 20:37:27 +00:00
-}
module CmdLine.GitAnnexShell.Fields where
import Annex.Common
2014-01-26 20:37:27 +00:00
import qualified Annex
import Git.FilePath
2014-01-26 20:37:27 +00:00
import Data.Char
{- A field, stored in Annex state, with a value sanity checker. -}
data Field = Field
{ fieldName :: String
, fieldCheck :: String -> Bool
}
getField :: Field -> Annex (Maybe String)
getField = Annex.getField . fieldName
remoteUUID :: Field
remoteUUID = Field "remoteuuid" $
-- does it look like a UUID?
all (\c -> isAlphaNum c || c == '-')
associatedFile :: Field
associatedFile = Field "associatedfile" $ \f ->
-- is the file a safe relative filename?
not (absoluteGitPath f) && not ("../" `isPrefixOf` f)
2014-01-26 20:37:27 +00:00
direct :: Field
direct = Field "direct" $ \f -> f == "1"
unlocked :: Field
unlocked = Field "unlocked" $ \f -> f == "1"
autoInit :: Field
autoInit = Field "autoinit" $ \f -> f == "1"