summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-14 13:47:22 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-14 13:47:22 -0400
commit949b3f69d0f2b2a5c32a00d05d09a0b312fad35a (patch)
treecc81f8d61652741e365309b86a8020edbce6318e /Command
parent1ac6217c74b63b9b154d5ee14ed72df8b5aa9268 (diff)
optimize: A new subcommand that either gets or drops file content as needed to work toward meeting the configured numcopies setting.
This is currently rather simplistic, though still useful. In the future, it could become smarter about what content is stored where, etc.
Diffstat (limited to 'Command')
-rw-r--r--Command/Fsck.hs2
-rw-r--r--Command/Optimize.hs35
2 files changed, 36 insertions, 1 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 529a5015a..cdc68581e 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -34,7 +34,7 @@ command = [repoCommand "fsck" (paramOptional $ paramRepeating paramPath) seek
"check for problems"]
seek :: [CommandSeek]
-seek = [withAttrFilesInGit "annex.numcopies" start]
+seek = [withNumCopies start]
start :: CommandStartAttrFile
start (file, attr) = notBareRepo $ isAnnexed file $ \(key, backend) -> do
diff --git a/Command/Optimize.hs b/Command/Optimize.hs
new file mode 100644
index 000000000..40625fc2f
--- /dev/null
+++ b/Command/Optimize.hs
@@ -0,0 +1,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