From 225199aff44949671b1fa848ce6d89945bd2f2f9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 19 Nov 2013 17:05:00 -0400 Subject: retrying --- Git/Destroyer.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Git') diff --git a/Git/Destroyer.hs b/Git/Destroyer.hs index 74a7941..7597be8 100644 --- a/Git/Destroyer.hs +++ b/Git/Destroyer.hs @@ -87,20 +87,20 @@ applyDamage l r = do `catchIO` \e -> error ("Failed to apply " ++ show action ++ " " ++ show f ++ ": " ++ show e ++ "(total damage: " ++ show l ++ ")") applyDamageAction :: DamageAction -> FilePath -> IO () -applyDamageAction Empty f = changeFile f $ do +applyDamageAction Empty f = withSaneMode f $ do nukeFile f writeFile f "" -applyDamageAction Reverse f = changeFile f $ +applyDamageAction Reverse f = withSaneMode f $ B.writeFile f =<< B.reverse <$> B.readFile f applyDamageAction Delete f = nukeFile f -applyDamageAction (AppendGarbage garbage) f = changeFile f $ +applyDamageAction (AppendGarbage garbage) f = withSaneMode f $ B.appendFile f garbage -applyDamageAction (PrependGarbage garbage) f = changeFile f $ do +applyDamageAction (PrependGarbage garbage) f = withSaneMode f $ do b <- B.readFile f B.writeFile f $ B.concat [garbage, b] -- When the byte is past the end of the file, wrap around. -- Does nothing to empty file. -applyDamageAction (CorruptByte n garbage) f = changeFile f $ do +applyDamageAction (CorruptByte n garbage) f = withSaneMode f $ do b <- B.readFile f let len = B.length b unless (len == 0) $ do @@ -113,6 +113,5 @@ applyDamageAction (CorruptByte n garbage) f = changeFile f $ do ] applyDamageAction (ScrambleFileMode mode) f = setFileMode f mode --- Files in git are often not writable, so fix up mode temporarily. -changeFile :: FilePath -> IO () -> IO () -changeFile f = withModifiedFileMode f (addModes [ownerWriteMode]) +withSaneMode :: FilePath -> IO () -> IO () +withSaneMode f = withModifiedFileMode f (addModes [ownerWriteMode, ownerReadMode]) -- cgit v1.2.3