git-annex/CmdLine/GitAnnexShell/Fields.hs
Joey Hess f776ac0a11
add unlocked flag for git-annex-shell recvkey
The direct flag is also set when sending unlocked content, to support old
versions of git-annex-shell. At some point, the direct flag will be
removed, and only the unlocked flag will be used.
2015-12-26 13:59:27 -04:00

42 lines
961 B
Haskell

{- git-annex-shell fields
-
- Copyright 2012 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module CmdLine.GitAnnexShell.Fields where
import Common.Annex
import qualified Annex
import Git.FilePath
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)
direct :: Field
direct = Field "direct" $ \f -> f == "1"
unlocked :: Field
unlocked = Field "unlocked" $ \f -> f == "1"
autoInit :: Field
autoInit = Field "autoinit" $ \f -> f == "1"