Ensure execute bit is set on directories when core.sharedrepsitory is set.

This commit is contained in:
Joey Hess 2013-11-18 18:05:37 -04:00
parent 0d0e21ea57
commit 310c549b5a
4 changed files with 25 additions and 13 deletions

View file

@ -386,7 +386,7 @@ setIndexSha :: Git.Ref -> Annex ()
setIndexSha ref = do setIndexSha ref = do
f <- fromRepo gitAnnexIndexStatus f <- fromRepo gitAnnexIndexStatus
liftIO $ writeFile f $ show ref ++ "\n" liftIO $ writeFile f $ show ref ++ "\n"
setAnnexPerm f setAnnexFilePerm f
{- Stages the journal into the index and returns an action that will {- Stages the journal into the index and returns an action that will
- clean up the staged journal files, which should only be run once - clean up the staged journal files, which should only be run once

View file

@ -6,7 +6,8 @@
-} -}
module Annex.Perms ( module Annex.Perms (
setAnnexPerm, setAnnexFilePerm,
setAnnexDirPerm,
annexFileMode, annexFileMode,
createAnnexDirectory, createAnnexDirectory,
noUmask, noUmask,
@ -33,17 +34,27 @@ withShared a = maybe startup a =<< Annex.getState Annex.shared
Annex.changeState $ \s -> s { Annex.shared = Just shared } Annex.changeState $ \s -> s { Annex.shared = Just shared }
a shared a shared
setAnnexFilePerm :: FilePath -> Annex ()
setAnnexFilePerm = setAnnexPerm False
setAnnexDirPerm :: FilePath -> Annex ()
setAnnexDirPerm = setAnnexPerm True
{- Sets appropriate file mode for a file or directory in the annex, {- Sets appropriate file mode for a file or directory in the annex,
- other than the content files and content directory. Normally, - other than the content files and content directory. Normally,
- use the default mode, but with core.sharedRepository set, - use the default mode, but with core.sharedRepository set,
- allow the group to write, etc. -} - allow the group to write, etc. -}
setAnnexPerm :: FilePath -> Annex () setAnnexPerm :: Bool -> FilePath -> Annex ()
setAnnexPerm file = unlessM crippledFileSystem $ setAnnexPerm isdir file = unlessM crippledFileSystem $
withShared $ liftIO . go withShared $ liftIO . go
where where
go GroupShared = groupWriteRead file go GroupShared = modifyFileMode file $ addModes $
groupSharedModes ++
if isdir then [ ownerExecuteMode, groupExecuteMode ] else []
go AllShared = modifyFileMode file $ addModes $ go AllShared = modifyFileMode file $ addModes $
[ ownerWriteMode, groupWriteMode ] ++ readModes readModes ++
[ ownerWriteMode, groupWriteMode ] ++
if isdir then executeModes else []
go _ = noop go _ = noop
{- Gets the appropriate mode to use for creating a file in the annex {- Gets the appropriate mode to use for creating a file in the annex
@ -54,10 +65,7 @@ annexFileMode = withShared $ return . go
go GroupShared = sharedmode go GroupShared = sharedmode
go AllShared = combineModes (sharedmode:readModes) go AllShared = combineModes (sharedmode:readModes)
go _ = stdFileMode go _ = stdFileMode
sharedmode = combineModes sharedmode = combineModes groupSharedModes
[ ownerWriteMode, groupWriteMode
, ownerReadMode, groupReadMode
]
{- Creates a directory inside the gitAnnexDir, including any parent {- Creates a directory inside the gitAnnexDir, including any parent
- directories. Makes directories with appropriate permissions. -} - directories. Makes directories with appropriate permissions. -}
@ -74,7 +82,7 @@ createAnnexDirectory dir = traverse dir [] =<< top
where where
done = forM_ below $ \p -> do done = forM_ below $ \p -> do
liftIO $ createDirectoryIfMissing True p liftIO $ createDirectoryIfMissing True p
setAnnexPerm p setAnnexDirPerm p
{- Blocks writing to the directory an annexed file is in, to prevent the {- Blocks writing to the directory an annexed file is in, to prevent the
- file accidentially being deleted. However, if core.sharedRepository - file accidentially being deleted. However, if core.sharedRepository

View file

@ -65,12 +65,15 @@ allowWrite :: FilePath -> IO ()
allowWrite f = modifyFileMode f $ addModes [ownerWriteMode] allowWrite f = modifyFileMode f $ addModes [ownerWriteMode]
{- Allows owner and group to read and write to a file. -} {- Allows owner and group to read and write to a file. -}
groupWriteRead :: FilePath -> IO () groupSharedModes :: [FileMode]
groupWriteRead f = modifyFileMode f $ addModes groupSharedModes =
[ ownerWriteMode, groupWriteMode [ ownerWriteMode, groupWriteMode
, ownerReadMode, groupReadMode , ownerReadMode, groupReadMode
] ]
groupWriteRead :: FilePath -> IO ()
groupWriteRead f = modifyFileMode f $ addModes groupSharedModes
checkMode :: FileMode -> FileMode -> Bool checkMode :: FileMode -> FileMode -> Bool
checkMode checkfor mode = checkfor `intersectFileModes` mode == checkfor checkMode checkfor mode = checkfor `intersectFileModes` mode == checkfor

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ git-annex (5.20131119) UNRELEASED; urgency=low
* dropunused, addunused: Allow "all" instead of a range to * dropunused, addunused: Allow "all" instead of a range to
act on all unused data. act on all unused data.
* Ensure execute bit is set on directories when core.sharedrepsitory is set.
-- Joey Hess <joeyh@debian.org> Mon, 18 Nov 2013 17:09:21 -0400 -- Joey Hess <joeyh@debian.org> Mon, 18 Nov 2013 17:09:21 -0400