honor core.sharedRepository settings in lockContent

The content file may not be owned by the user running git-annex, in which
case, setting the owner write bit was not enough to let lockContent
act on the file. However, with some core.sharedRepository configs, the file
should be writable by the user's group. So, the thing to do is to call
thawContent on it.
This commit is contained in:
Joey Hess 2015-05-19 14:53:19 -04:00
parent c0cc22a657
commit b47c9fd587
2 changed files with 6 additions and 17 deletions

View file

@ -182,11 +182,11 @@ lockContent key a = do
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
{- Since content files are stored with the write bit disabled, have {- Since content files are stored with the write bit disabled, have
- to fiddle with permissions to open for an exclusive lock. -} - to fiddle with permissions to open for an exclusive lock. -}
lock contentfile Nothing = trylock $ liftIO $ lock contentfile Nothing = trylock $ bracket_
withModifiedFileMode contentfile (thawContent contentfile)
(`unionFileModes` ownerWriteMode) $ (freezeContent contentfile)
maybe alreadylocked return (maybe alreadylocked return
=<< tryLockExclusive Nothing contentfile =<< liftIO (tryLockExclusive Nothing contentfile))
lock _ (Just lockfile) = trylock $ do lock _ (Just lockfile) = trylock $ do
mode <- annexFileMode mode <- annexFileMode
maybe alreadylocked return maybe alreadylocked return

View file

@ -22,15 +22,12 @@ import Utility.Exception
{- Applies a conversion function to a file's mode. -} {- Applies a conversion function to a file's mode. -}
modifyFileMode :: FilePath -> (FileMode -> FileMode) -> IO () modifyFileMode :: FilePath -> (FileMode -> FileMode) -> IO ()
modifyFileMode f convert = void $ modifyFileMode' f convert modifyFileMode f convert = do
modifyFileMode' :: FilePath -> (FileMode -> FileMode) -> IO FileMode
modifyFileMode' f convert = do
s <- getFileStatus f s <- getFileStatus f
let old = fileMode s let old = fileMode s
let new = convert old let new = convert old
when (new /= old) $ when (new /= old) $
setFileMode f new setFileMode f new
return old
{- Adds the specified FileModes to the input mode, leaving the rest {- Adds the specified FileModes to the input mode, leaving the rest
- unchanged. -} - unchanged. -}
@ -41,14 +38,6 @@ addModes ms m = combineModes (m:ms)
removeModes :: [FileMode] -> FileMode -> FileMode removeModes :: [FileMode] -> FileMode -> FileMode
removeModes ms m = m `intersectFileModes` complement (combineModes ms) removeModes ms m = m `intersectFileModes` complement (combineModes ms)
{- Runs an action after changing a file's mode, then restores the old mode. -}
withModifiedFileMode :: FilePath -> (FileMode -> FileMode) -> IO a -> IO a
withModifiedFileMode file convert a = bracket setup cleanup go
where
setup = modifyFileMode' file convert
cleanup oldmode = modifyFileMode file (const oldmode)
go _ = a
writeModes :: [FileMode] writeModes :: [FileMode]
writeModes = [ownerWriteMode, groupWriteMode, otherWriteMode] writeModes = [ownerWriteMode, groupWriteMode, otherWriteMode]