diff options
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Drop.hs | 8 | ||||
-rw-r--r-- | Command/Get.hs | 11 | ||||
-rw-r--r-- | Command/Optimize.hs | 34 |
3 files changed, 12 insertions, 41 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs index 8f886f283..32cb81e80 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -29,13 +29,15 @@ seek = [withNumCopies start] {- Indicates a file's content is not wanted anymore, and should be removed - if it's safe to do so. -} start :: CommandStartAttrFile -start (file, numcopies) = isAnnexed file $ \(key, _) -> do +start (file, attr) = isAnnexed file $ \(key, _) -> do present <- inAnnex key if present - then do + then autoCopies key (>) numcopies $ do showStart "drop" file - next $ perform key $ readMaybe numcopies + next $ perform key numcopies else stop + where + numcopies = readMaybe attr perform :: Key -> Maybe Int -> CommandPerform perform key numcopies = do diff --git a/Command/Get.hs b/Command/Get.hs index e0436a868..1a50158e3 100644 --- a/Command/Get.hs +++ b/Command/Get.hs @@ -13,6 +13,7 @@ import qualified Remote import Types import Content import Messages +import Utility import qualified Command.Move command :: [Command] @@ -20,14 +21,14 @@ command = [repoCommand "get" paramPath seek "make content of annexed files available"] seek :: [CommandSeek] -seek = [withFilesInGit start] +seek = [withNumCopies start] -start :: CommandStartString -start file = isAnnexed file $ \(key, _) -> do +start :: CommandStartAttrFile +start (file, attr) = isAnnexed file $ \(key, _) -> do inannex <- inAnnex key if inannex then stop - else do + else autoCopies key (<) numcopies $ do showStart "get" file from <- Annex.getState Annex.fromremote case from of @@ -35,6 +36,8 @@ start file = isAnnexed file $ \(key, _) -> do Just name -> do src <- Remote.byName name next $ Command.Move.fromPerform src False key + where + numcopies = readMaybe attr perform :: Key -> CommandPerform perform key = do diff --git a/Command/Optimize.hs b/Command/Optimize.hs deleted file mode 100644 index 1a2b2237f..000000000 --- a/Command/Optimize.hs +++ /dev/null @@ -1,34 +0,0 @@ -{- 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 $ readMaybe attr - (_, 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 |