summaryrefslogtreecommitdiff
path: root/Backend/WORM.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Backend/WORM.hs')
-rw-r--r--Backend/WORM.hs34
1 files changed, 33 insertions, 1 deletions
diff --git a/Backend/WORM.hs b/Backend/WORM.hs
index 848386ecd..21b3876b9 100644
--- a/Backend/WORM.hs
+++ b/Backend/WORM.hs
@@ -10,14 +10,22 @@ module Backend.WORM (backend) where
import Control.Monad.State
import System.FilePath
import System.Posix.Files
+import System.Posix.Types
+import System.Directory
+import Data.String.Utils
import qualified Backend.File
import TypeInternals
+import Locations
+import qualified Annex
+import Core
+import Messages
backend :: Backend
backend = Backend.File.backend {
name = "WORM",
- getKey = keyValue
+ getKey = keyValue,
+ fsckKey = Backend.File.checkKey checkKeySize
}
-- The key is formed from the file size, modification time, and the
@@ -36,3 +44,27 @@ keyValue file = do
(show $ fileSize stat)
base = takeFileName file
sep = ":"
+
+{- Extracts the file size from a key. -}
+keySize :: Key -> FileOffset
+keySize key = read $ section !! 2
+ where
+ section = split ":" (keyName key)
+
+{- The size of the data for a key is checked against the size encoded in
+ - the key. Note that the modification time is not checked. -}
+checkKeySize :: Key -> Annex Bool
+checkKeySize key = do
+ g <- Annex.gitRepo
+ let file = annexLocation g key
+ present <- liftIO $ doesFileExist file
+ if (not present)
+ then return True
+ else do
+ s <- liftIO $ getFileStatus file
+ if (fileSize s == keySize key)
+ then return True
+ else do
+ dest <- moveBad key
+ showNote $ "bad file size (moved to "++dest++")"
+ return False