From 04539d16718265441c607da08d3e27d959f749c6 Mon Sep 17 00:00:00 2001
From: Joey Hess <joey@kitenet.net>
Date: Wed, 23 Mar 2011 02:42:14 -0400
Subject: [PATCH] improve size change display

---
 Backend.hs   | 14 +++-----------
 DataUnits.hs |  8 +++++++-
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/Backend.hs b/Backend.hs
index fe61739e83..0ee56d2623 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -192,15 +192,7 @@ checkKeySize key = do
 				then return True
 				else do
 					dest <- moveBad key
-					warning $ badsizeNote dest size size'
+					warning $ "Bad file size (" ++
+						compareSizes True size size' ++ 
+						"); moved to " ++ dest
 					return False
-
-badsizeNote :: FilePath -> Integer -> Integer -> String
-badsizeNote dest expected got = "Bad file size (" ++ aside ++ "); moved to " ++ dest
-	where
-		expected' = roughSize True expected
-		got' = roughSize True got
-		aside = 
-			if expected' == got'
-				then show got ++ " not " ++ show expected
-				else got' ++ " not " ++ expected'
diff --git a/DataUnits.hs b/DataUnits.hs
index 329bf7e580..c2845affea 100644
--- a/DataUnits.hs
+++ b/DataUnits.hs
@@ -5,7 +5,7 @@
  - Licensed under the GNU GPL version 3 or higher.
  -}
 
-module DataUnits (roughSize) where
+module DataUnits (roughSize, compareSizes) where
 
 {- And now a rant: 
  -
@@ -63,3 +63,9 @@ roughSize short i
 		plural n u
 			| n == 1 = u
 			| otherwise = u ++ "s"
+
+compareSizes :: Bool -> Integer -> Integer -> String
+compareSizes short old new
+	| old > new = roughSize short (old - new) ++ " smaller"
+	| old < new = roughSize short (new - old) ++ " larger"
+	| otherwise = "same"