summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-07 17:26:21 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-07 17:26:21 -0400
commitea8ccaa3d5416044ca69e4a3dcb7b879aec0ff4c (patch)
treef04998a4a1500d47f150dead5abadd9e0d110c61
parent55b92860ceb099614ac9ebe4c37e92b57ad6a430 (diff)
rough in fsck
-rw-r--r--Command/Fsck.hs46
-rw-r--r--TypeInternals.hs2
2 files changed, 39 insertions, 9 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index bd5a9ad7f..c86f30ff8 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -7,15 +7,10 @@
module Command.Fsck where
-import Control.Monad.State (liftIO)
-import System.Posix.Files
-import System.Directory
-
import Command
-import qualified Annex
import Types
-import Utility
import Core
+import qualified Data.Map as M
{- Checks the whole annex for problems. -}
start :: SubCmdStart
@@ -35,5 +30,40 @@ perform = do
checkUnused :: Annex Bool
checkUnused = do
showNote "checking for unused data..."
- -- TODO
- return False
+ unused <- unusedKeys
+ if (null unused)
+ then return True
+ else do
+ showLongNote $ w unused
+ return False
+ where
+ w u = unlines $ [
+ "Some annexed data is no longer pointed to by any file.",
+ "If this data is no longer needed, it can be removed using git-annex dropkey:"
+ ] ++ map show u
+
+unusedKeys :: Annex [Key]
+unusedKeys = do
+ present <- getKeysPresent
+ referenced <- getKeysReferenced
+
+ -- Constructing a single map, of the set that tends to be smaller,
+ -- appears more efficient in both memory and CPU than constructing
+ -- and taking the M.difference of two maps.
+ let present_m = existsMap present
+ let unused_m = remove referenced present_m
+ return $ M.keys unused_m
+ where
+ remove [] m = m
+ remove (x:xs) m = remove xs $ M.delete x m
+
+existsMap :: Ord k => [k] -> M.Map k Int
+existsMap l = M.fromList $ map (\k -> (k, 1)) l
+
+getKeysPresent :: Annex [Key]
+getKeysPresent = do
+ return []
+
+getKeysReferenced :: Annex [Key]
+getKeysReferenced = do
+ return []
diff --git a/TypeInternals.hs b/TypeInternals.hs
index 46c92cb59..4b5cff9d9 100644
--- a/TypeInternals.hs
+++ b/TypeInternals.hs
@@ -39,7 +39,7 @@ type Annex = StateT AnnexState IO
-- annexed filenames are mapped through a backend into keys
type KeyName = String
type BackendName = String
-data Key = Key (BackendName, KeyName) deriving (Eq)
+data Key = Key (BackendName, KeyName) deriving (Eq, Ord)
-- constructs a key in a backend
genKey :: Backend -> KeyName -> Key