summaryrefslogtreecommitdiff
path: root/CmdLine/GitAnnexShell/Fields.hs
blob: efe22971dde74c47b7259c258cfee21e895c711a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{- 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 Annex.Common
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"