summaryrefslogtreecommitdiff
path: root/Backend/WORM.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-13 14:59:27 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-13 14:59:27 -0400
commit5fa25a812a8a03af9f6a5fdb3d06eb4d89ee06f5 (patch)
tree467341e52d23660eee3dc05c9935c961801374e5 /Backend/WORM.hs
parentd4d65a3c923de1eece50463145e875326bfe57e9 (diff)
fsck improvements
* fsck: Check if annex.numcopies is satisfied. * fsck: Verify the sha1 of files when the SHA1 backend is used. * fsck: Verify the size of files when the WORM backend is used. * fsck: Allow specifying individual files to fsk if fscking everything is not desired. * fsck: Fix bug, introduced in 0.04, in detection of unused data.
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