2012-07-02 12:35:15 +00:00
|
|
|
{- git-annex fields
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Fields where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import qualified Annex
|
|
|
|
|
|
|
|
import Data.Char
|
|
|
|
|
|
|
|
{- A field, stored in Annex state, with a value sanity checker. -}
|
|
|
|
data Field = Field
|
|
|
|
{ fieldName :: String
|
2012-07-02 15:08:50 +00:00
|
|
|
, fieldCheck :: String -> Bool
|
2012-07-02 12:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remoteUUID :: Field
|
|
|
|
remoteUUID = Field "remoteuuid" $
|
|
|
|
-- does it look like a UUID?
|
2012-07-02 15:08:50 +00:00
|
|
|
all (\c -> isAlphaNum c || c == '-')
|
2012-07-02 12:35:15 +00:00
|
|
|
|
|
|
|
associatedFile :: Field
|
2012-07-02 15:08:50 +00:00
|
|
|
associatedFile = Field "associatedfile" $ \f ->
|
|
|
|
-- is the file a safe relative filename?
|
|
|
|
not (isAbsolute f) && not ("../" `isPrefixOf` f)
|
2012-07-02 12:35:15 +00:00
|
|
|
|
|
|
|
getField :: Field -> Annex (Maybe String)
|
|
|
|
getField = Annex.getField . fieldName
|