This commit is contained in:
Joey Hess 2012-03-11 21:08:48 -04:00
parent 5df18b311a
commit 83bbb3bc93

View file

@ -54,14 +54,11 @@ start = do
next action next action
checkUnused :: CommandPerform checkUnused :: CommandPerform
checkUnused = do checkUnused = chain 0
unused <- findunused =<< Annex.getState Annex.fast [ check "" unusedMsg $ findunused =<< Annex.getState Annex.fast
stalebad <- staleKeysPrune gitAnnexBadDir , check "bad" staleBadMsg $ staleKeysPrune gitAnnexBadDir
staletmp <- staleKeysPrune gitAnnexTmpDir , check "tmp" staleTmpMsg $ staleKeysPrune gitAnnexTmpDir
_ <- list "" unusedMsg unused 0 >>= ]
list "bad" staleBadMsg stalebad >>=
list "tmp" staleTmpMsg staletmp
next $ return True
where where
findunused True = do findunused True = do
showNote "fast mode enabled; only finding stale files" showNote "fast mode enabled; only finding stale files"
@ -69,25 +66,32 @@ checkUnused = do
findunused False = do findunused False = do
showAction "checking for unused data" showAction "checking for unused data"
excludeReferenced =<< getKeysPresent excludeReferenced =<< getKeysPresent
list file msg l c = do chain _ [] = next $ return True
let unusedlist = number c l chain v (a:as) = do
unless (null l) $ showLongNote $ msg unusedlist v' <- a v
writeUnusedFile file unusedlist chain v' as
return $ c + length l
checkRemoteUnused :: String -> CommandPerform checkRemoteUnused :: String -> CommandPerform
checkRemoteUnused name = do checkRemoteUnused name = go =<< fromJust <$> Remote.byName (Just name)
checkRemoteUnused' =<< fromJust <$> Remote.byName (Just name) where
next $ return True go r = do
showAction "checking for unused data"
_ <- check "" (remoteUnusedMsg r) (remoteunused r) 0
next $ return True
remoteunused r =
excludeReferenced =<< loggedKeysFor (Remote.uuid r)
checkRemoteUnused' :: Remote -> Annex () check :: FilePath -> ([(Int, Key)] -> String) -> Annex [Key] -> Int -> Annex Int
checkRemoteUnused' r = do check file msg a c = do
showAction "checking for unused data" l <- a
remotehas <- loggedKeysFor (Remote.uuid r) let unusedlist = number c l
remoteunused <- excludeReferenced remotehas unless (null l) $ showLongNote $ msg unusedlist
let list = number 0 remoteunused writeUnusedFile file unusedlist
writeUnusedFile "" list return $ c + length l
unless (null remoteunused) $ showLongNote $ remoteUnusedMsg r list
number :: Int -> [a] -> [(Int, a)]
number _ [] = []
number n (x:xs) = (n+1, x) : number (n+1) xs
writeUnusedFile :: FilePath -> [(Int, Key)] -> Annex () writeUnusedFile :: FilePath -> [(Int, Key)] -> Annex ()
writeUnusedFile prefix l = do writeUnusedFile prefix l = do
@ -101,10 +105,6 @@ table l = " NUMBER KEY" : map cols l
cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ show k cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ show k
pad n s = s ++ replicate (n - length s) ' ' pad n s = s ++ replicate (n - length s) ' '
number :: Int -> [a] -> [(Int, a)]
number _ [] = []
number n (x:xs) = (n+1, x) : number (n+1) xs
staleTmpMsg :: [(Int, Key)] -> String staleTmpMsg :: [(Int, Key)] -> String
staleTmpMsg t = unlines $ staleTmpMsg t = unlines $
["Some partially transferred data exists in temporary files:"] ["Some partially transferred data exists in temporary files:"]