From 313f29e64caa94faac481523fa78d1185f377d83 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 24 Feb 2014 20:08:19 -0400 Subject: Add swapping 2 files test case. --- Git/Destroyer.hs | 14 +++++++++++++- debian/changelog | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Git/Destroyer.hs b/Git/Destroyer.hs index afefefa..a84bc60 100644 --- a/Git/Destroyer.hs +++ b/Git/Destroyer.hs @@ -2,7 +2,7 @@ - - Use with caution! - - - Copyright 2013 Joey Hess + - Copyright 2013, 2014 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -17,6 +17,7 @@ import Common import Git import Utility.QuickCheck import Utility.FileMode +import Utility.Tmp import qualified Data.ByteString as B import Data.Word @@ -31,6 +32,7 @@ data Damage | PrependGarbage FileSelector B.ByteString | CorruptByte FileSelector Int Word8 | ScrambleFileMode FileSelector FileMode + | SwapFiles FileSelector FileSelector deriving (Read, Show) instance Arbitrary Damage where @@ -47,6 +49,9 @@ instance Arbitrary Damage where , ScrambleFileMode <$> arbitrary <*> nonNegative arbitrarySizedIntegral + , SwapFiles + <$> arbitrary + <*> arbitrary ] where garbage = B.pack <$> arbitrary `suchThat` (not . null) @@ -124,6 +129,13 @@ applyDamage ds r = do ScrambleFileMode s mode -> withfile s $ \f -> setFileMode f mode + SwapFiles a b -> + withfile a $ \fa -> + withfile b $ \fb -> + withTmpFile "swap" $ \tmp _ -> do + moveFile fa tmp + moveFile fb fa + moveFile tmp fa where -- A broken .git/config is not recoverable. skipped f = f `elem` [ "config" ] diff --git a/debian/changelog b/debian/changelog index bcaccce..6222f5b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ git-repair (1.20140116) UNRELEASED; urgency=medium * Optimise unpacking of pack files, and avoid repeated error messages about corrupt pack files. + * Add swapping 2 files test case. -- Joey Hess Mon, 24 Feb 2014 19:39:51 -0400 -- cgit v1.2.3