aboutsummaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-06-02 14:20:38 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-06-02 14:20:38 -0400
commit72741df36b661ddcee900ab0f0e98357034f7b45 (patch)
tree758f332e2e39ba93e0b0eee8446cd1e48536987d /Annex
parent7dc6e0c0a087c945ae50d4165076b1123ff31b84 (diff)
get --incomplete: New option to resume any interrupted downloads.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Content.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs
index 28ca99544..5e7dd322b 100644
--- a/Annex/Content.hs
+++ b/Annex/Content.hs
@@ -35,9 +35,11 @@ module Annex.Content (
thawContent,
dirKeys,
withObjectLoc,
+ staleKeysPrune,
) where
import System.IO.Unsafe (unsafeInterleaveIO)
+import qualified Data.Set as S
import Common.Annex
import Logs.Location
@@ -663,3 +665,37 @@ dirKeys dirspec = do
, return []
)
+{- Looks in the specified directory for bad/tmp keys, and returns a list
+ - of those that might still have value, or might be stale and removable.
+ -
+ - Also, stale keys that can be proven to have no value
+ - (ie, their content is already present) are deleted.
+ -}
+staleKeysPrune :: (Git.Repo -> FilePath) -> Bool -> Annex [Key]
+staleKeysPrune dirspec nottransferred = do
+ contents <- dirKeys dirspec
+
+ dups <- filterM inAnnex contents
+ let stale = contents `exclude` dups
+
+ dir <- fromRepo dirspec
+ liftIO $ forM_ dups $ \t -> removeFile $ dir </> keyFile t
+
+ if nottransferred
+ then do
+ inprogress <- S.fromList . map (transferKey . fst)
+ <$> getTransfers
+ return $ filter (`S.notMember` inprogress) stale
+ else return stale
+
+{- Finds items in the first, smaller list, that are not
+ - present in the second, larger list.
+ -
+ - Constructing a single set, of the list that tends to be
+ - smaller, appears more efficient in both memory and CPU
+ - than constructing and taking the S.difference of two sets. -}
+exclude :: Ord a => [a] -> [a] -> [a]
+exclude [] _ = [] -- optimisation
+exclude smaller larger = S.toList $ remove larger $ S.fromList smaller
+ where
+ remove a b = foldl (flip S.delete) b a