aboutsummaryrefslogtreecommitdiff
path: root/Command/Optimize.hs
blob: 40625fc2f04bfa9bf949c6edc94efb4c73e13b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{- git-annex command
 -
 - Copyright 2011 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.Optimize where

import Command
import Utility
import LocationLog
import Trust
import Config
import qualified Command.Get
import qualified Command.Drop

command :: [Command]
command = [repoCommand "optimize" (paramOptional $ paramRepeating paramPath) seek
	"get or drop content to best use available space"]

seek :: [CommandSeek]
seek = [withNumCopies start]

start :: CommandStartAttrFile
start p@(file, attr) = notBareRepo $ isAnnexed file $ \(key, _) -> do
	needed <- getNumCopies numcopies
	(_, safelocations) <- trustPartition UnTrusted =<< keyLocations key
	dispatch needed (length safelocations)
	where
		dispatch needed present
			| present < needed = Command.Get.start file
			| present > needed = Command.Drop.start p
			| otherwise = stop
		numcopies = readMaybe attr :: Maybe Int