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.
This commit is contained in:
parent
d4d65a3c92
commit
5fa25a812a
15 changed files with 236 additions and 31 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue