diff --git a/Annex/Content.hs b/Annex/Content.hs index c23d7e951a..379ff07854 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -182,11 +182,11 @@ lockContent key a = do #ifndef mingw32_HOST_OS {- Since content files are stored with the write bit disabled, have - to fiddle with permissions to open for an exclusive lock. -} - lock contentfile Nothing = trylock $ liftIO $ - withModifiedFileMode contentfile - (`unionFileModes` ownerWriteMode) $ - maybe alreadylocked return - =<< tryLockExclusive Nothing contentfile + lock contentfile Nothing = trylock $ bracket_ + (thawContent contentfile) + (freezeContent contentfile) + (maybe alreadylocked return + =<< liftIO (tryLockExclusive Nothing contentfile)) lock _ (Just lockfile) = trylock $ do mode <- annexFileMode maybe alreadylocked return diff --git a/Utility/FileMode.hs b/Utility/FileMode.hs index 201b8451c5..fdf1b56ba9 100644 --- a/Utility/FileMode.hs +++ b/Utility/FileMode.hs @@ -22,15 +22,12 @@ import Utility.Exception {- Applies a conversion function to a file's mode. -} modifyFileMode :: FilePath -> (FileMode -> FileMode) -> IO () -modifyFileMode f convert = void $ modifyFileMode' f convert -modifyFileMode' :: FilePath -> (FileMode -> FileMode) -> IO FileMode -modifyFileMode' f convert = do +modifyFileMode f convert = do s <- getFileStatus f let old = fileMode s let new = convert old when (new /= old) $ setFileMode f new - return old {- Adds the specified FileModes to the input mode, leaving the rest - unchanged. -} @@ -41,14 +38,6 @@ addModes ms m = combineModes (m:ms) removeModes :: [FileMode] -> FileMode -> FileMode 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 = [ownerWriteMode, groupWriteMode, otherWriteMode]