2012-04-21 20:59:49 +00:00
|
|
|
{- git-annex file permissions
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Perms (
|
|
|
|
setAnnexPerm,
|
|
|
|
annexFileMode,
|
|
|
|
createAnnexDirectory,
|
|
|
|
noUmask,
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Utility.FileMode
|
|
|
|
import Git.SharedRepository
|
2012-04-21 23:42:49 +00:00
|
|
|
import qualified Annex
|
2012-04-21 20:59:49 +00:00
|
|
|
|
|
|
|
import System.Posix.Types
|
|
|
|
|
2012-04-21 23:42:49 +00:00
|
|
|
withShared :: (SharedRepository -> Annex a) -> Annex a
|
|
|
|
withShared a = maybe startup a =<< Annex.getState Annex.shared
|
|
|
|
where
|
|
|
|
startup = do
|
|
|
|
shared <- fromRepo getSharedRepository
|
|
|
|
Annex.changeState $ \s -> s { Annex.shared = Just shared }
|
|
|
|
a shared
|
|
|
|
|
2012-04-21 20:59:49 +00:00
|
|
|
{- Sets appropriate file mode for a file or directory in the annex,
|
|
|
|
- other than the content files and content directory. Normally,
|
|
|
|
- use the default mode, but with core.sharedRepository set,
|
|
|
|
- allow the group to write, etc. -}
|
|
|
|
setAnnexPerm :: FilePath -> Annex ()
|
2012-04-21 23:42:49 +00:00
|
|
|
setAnnexPerm file = withShared $ liftIO . go
|
2012-04-21 20:59:49 +00:00
|
|
|
where
|
|
|
|
go GroupShared = groupWriteRead file
|
|
|
|
go AllShared = modifyFileMode file $ addModes $
|
|
|
|
[ ownerWriteMode, groupWriteMode ] ++ readModes
|
2012-04-22 03:32:33 +00:00
|
|
|
go _ = noop
|
2012-04-21 20:59:49 +00:00
|
|
|
|
|
|
|
{- Gets the appropriate mode to use for creating a file in the annex
|
|
|
|
- (other than content files, which are locked down more). -}
|
|
|
|
annexFileMode :: Annex FileMode
|
2012-04-21 23:42:49 +00:00
|
|
|
annexFileMode = withShared $ return . go
|
2012-04-21 20:59:49 +00:00
|
|
|
where
|
|
|
|
go GroupShared = sharedmode
|
|
|
|
go AllShared = combineModes (sharedmode:readModes)
|
|
|
|
go _ = stdFileMode
|
|
|
|
sharedmode = combineModes
|
|
|
|
[ ownerWriteMode, groupWriteMode
|
|
|
|
, ownerReadMode, groupReadMode
|
|
|
|
]
|
|
|
|
|
|
|
|
{- Creates a directory inside the gitAnnexDir, including any parent
|
|
|
|
- directories. Makes directories with appropriate permissions. -}
|
|
|
|
createAnnexDirectory :: FilePath -> Annex ()
|
|
|
|
createAnnexDirectory dir = traverse dir [] =<< top
|
|
|
|
where
|
|
|
|
top = parentDir <$> fromRepo gitAnnexDir
|
|
|
|
traverse d below stop
|
|
|
|
| d `equalFilePath` stop = done
|
|
|
|
| otherwise = ifM (liftIO $ doesDirectoryExist d)
|
|
|
|
( done
|
|
|
|
, traverse (parentDir d) (d:below) stop
|
|
|
|
)
|
|
|
|
where
|
|
|
|
done = forM_ below $ \p -> do
|
|
|
|
liftIO $ createDirectory p
|
|
|
|
setAnnexPerm p
|