summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2013-11-19 17:05:00 -0400
committerJoey Hess <joey@kitenet.net>2013-11-19 17:05:00 -0400
commit225199aff44949671b1fa848ce6d89945bd2f2f9 (patch)
tree33c549ae6881f07d23546a55a6a7156a9a5b5999 /Git
parent46e0d4b8985dfd8dc69d684d86d8ab2b1ac44e82 (diff)
downloadgit-repair-225199aff44949671b1fa848ce6d89945bd2f2f9.tar.gz
retrying
Diffstat (limited to 'Git')
-rw-r--r--Git/Destroyer.hs15
1 files changed, 7 insertions, 8 deletions
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])