summaryrefslogtreecommitdiff
path: root/Command/Drop.hs
blob: 168aa92bd6884c155153f3c4266f103d1c1016f0 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
{- git-annex command
 -
 - Copyright 2010 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.Drop where

import Control.Monad (when)

import Command
import qualified Backend
import LocationLog
import Types
import Core
import Messages
import Utility

seek :: [SubCmdSeek]
seek = [withAttrFilesInGit "git-annex-numcopies" start]

{- Indicates a file's content is not wanted anymore, and should be removed
 - if it's safe to do so. -}
start :: SubCmdStartAttrFile
start (file, attr) = isAnnexed file $ \(key, backend) -> do
	inbackend <- Backend.hasKey key
	if not inbackend
		then return Nothing
		else do
			showStart "drop" file
			return $ Just $ perform key backend numcopies
	where
		numcopies = readMaybe attr :: Maybe Int

perform :: Key -> Backend -> Maybe Int -> SubCmdPerform
perform key backend numcopies = do
	success <- Backend.removeKey backend key numcopies
	if success
		then return $ Just $ cleanup key
		else return Nothing

cleanup :: Key -> SubCmdCleanup
cleanup key = do
	inannex <- inAnnex key
	when inannex $ removeAnnex key
	logStatus key ValueMissing
	return True