2012-10-10 19:15:56 +00:00
|
|
|
{- git-annex standard repository groups
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2012-10-10 20:04:28 +00:00
|
|
|
module Types.StandardGroups where
|
2012-10-10 19:27:25 +00:00
|
|
|
|
2013-04-26 03:44:55 +00:00
|
|
|
import Types.Remote (RemoteConfig)
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
import Data.Maybe
|
|
|
|
|
2014-01-01 23:58:02 +00:00
|
|
|
type PreferredContentExpression = String
|
|
|
|
|
2013-01-21 08:18:05 +00:00
|
|
|
data StandardGroup
|
|
|
|
= ClientGroup
|
|
|
|
| TransferGroup
|
|
|
|
| BackupGroup
|
2013-03-16 16:09:22 +00:00
|
|
|
| IncrementalBackupGroup
|
2013-01-21 08:18:05 +00:00
|
|
|
| SmallArchiveGroup
|
|
|
|
| FullArchiveGroup
|
|
|
|
| SourceGroup
|
|
|
|
| ManualGroup
|
2013-04-25 16:23:36 +00:00
|
|
|
| PublicGroup
|
2013-03-31 21:10:25 +00:00
|
|
|
| UnwantedGroup
|
2012-10-10 20:04:28 +00:00
|
|
|
deriving (Eq, Ord, Enum, Bounded, Show)
|
2012-10-10 19:15:56 +00:00
|
|
|
|
|
|
|
fromStandardGroup :: StandardGroup -> String
|
|
|
|
fromStandardGroup ClientGroup = "client"
|
|
|
|
fromStandardGroup TransferGroup = "transfer"
|
|
|
|
fromStandardGroup BackupGroup = "backup"
|
2013-03-16 15:17:53 +00:00
|
|
|
fromStandardGroup IncrementalBackupGroup = "incrementalbackup"
|
2012-11-24 20:30:15 +00:00
|
|
|
fromStandardGroup SmallArchiveGroup = "smallarchive"
|
|
|
|
fromStandardGroup FullArchiveGroup = "archive"
|
2013-01-21 08:18:05 +00:00
|
|
|
fromStandardGroup SourceGroup = "source"
|
|
|
|
fromStandardGroup ManualGroup = "manual"
|
2013-04-25 16:23:36 +00:00
|
|
|
fromStandardGroup PublicGroup = "public"
|
2013-03-31 21:10:25 +00:00
|
|
|
fromStandardGroup UnwantedGroup = "unwanted"
|
2012-10-10 19:15:56 +00:00
|
|
|
|
|
|
|
toStandardGroup :: String -> Maybe StandardGroup
|
|
|
|
toStandardGroup "client" = Just ClientGroup
|
|
|
|
toStandardGroup "transfer" = Just TransferGroup
|
|
|
|
toStandardGroup "backup" = Just BackupGroup
|
2013-03-16 15:17:53 +00:00
|
|
|
toStandardGroup "incrementalbackup" = Just IncrementalBackupGroup
|
2012-11-24 20:30:15 +00:00
|
|
|
toStandardGroup "smallarchive" = Just SmallArchiveGroup
|
|
|
|
toStandardGroup "archive" = Just FullArchiveGroup
|
2013-01-21 08:18:05 +00:00
|
|
|
toStandardGroup "source" = Just SourceGroup
|
|
|
|
toStandardGroup "manual" = Just ManualGroup
|
2013-04-25 16:23:36 +00:00
|
|
|
toStandardGroup "public" = Just PublicGroup
|
2013-03-31 21:10:25 +00:00
|
|
|
toStandardGroup "unwanted" = Just UnwantedGroup
|
2012-10-10 19:15:56 +00:00
|
|
|
toStandardGroup _ = Nothing
|
|
|
|
|
2013-04-26 17:00:14 +00:00
|
|
|
descStandardGroup :: StandardGroup -> String
|
|
|
|
descStandardGroup ClientGroup = "client: a repository on your computer"
|
|
|
|
descStandardGroup TransferGroup = "transfer: distributes files to clients"
|
|
|
|
descStandardGroup BackupGroup = "full backup: backs up all files"
|
|
|
|
descStandardGroup IncrementalBackupGroup = "incremental backup: backs up files not backed up elsewhere"
|
|
|
|
descStandardGroup SmallArchiveGroup = "small archive: archives files located in \"archive\" directories"
|
|
|
|
descStandardGroup FullArchiveGroup = "full archive: archives all files not archived elsewhere"
|
|
|
|
descStandardGroup SourceGroup = "file source: moves files on to other repositories"
|
|
|
|
descStandardGroup ManualGroup = "manual mode: only stores files you manually choose"
|
|
|
|
descStandardGroup UnwantedGroup = "unwanted: remove content from this repository"
|
|
|
|
descStandardGroup PublicGroup = "public: publishes files located in an associated directory"
|
2013-04-26 03:44:55 +00:00
|
|
|
|
2013-04-26 17:00:14 +00:00
|
|
|
associatedDirectory :: Maybe RemoteConfig -> StandardGroup -> Maybe FilePath
|
|
|
|
associatedDirectory _ SmallArchiveGroup = Just "archive"
|
|
|
|
associatedDirectory _ FullArchiveGroup = Just "archive"
|
|
|
|
associatedDirectory (Just c) PublicGroup = Just $
|
2013-04-26 03:44:55 +00:00
|
|
|
fromMaybe "public" $ M.lookup "preferreddir" c
|
2013-04-26 17:00:14 +00:00
|
|
|
associatedDirectory Nothing PublicGroup = Just "public"
|
|
|
|
associatedDirectory _ _ = Nothing
|
2012-10-10 20:04:28 +00:00
|
|
|
|
2012-10-10 19:15:56 +00:00
|
|
|
{- See doc/preferred_content.mdwn for explanations of these expressions. -}
|
2014-01-01 23:58:02 +00:00
|
|
|
preferredContent :: StandardGroup -> PreferredContentExpression
|
2013-04-06 22:29:52 +00:00
|
|
|
preferredContent ClientGroup = lastResort $
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
"((exclude=*/archive/* and exclude=archive/*) or (" ++ notArchived ++ ")) and not unused"
|
2013-04-06 22:29:52 +00:00
|
|
|
preferredContent TransferGroup = lastResort $
|
|
|
|
"not (inallgroup=client and copies=client:2) and (" ++ preferredContent ClientGroup ++ ")"
|
2014-01-23 20:36:15 +00:00
|
|
|
preferredContent BackupGroup = "include=* or unused"
|
2013-09-26 03:19:01 +00:00
|
|
|
preferredContent IncrementalBackupGroup = lastResort
|
2014-01-23 20:36:15 +00:00
|
|
|
"(include=* or unused) and (not copies=incrementalbackup:1)"
|
2013-03-31 23:00:43 +00:00
|
|
|
preferredContent SmallArchiveGroup = lastResort $
|
2013-04-06 22:29:52 +00:00
|
|
|
"(include=*/archive/* or include=archive/*) and (" ++ preferredContent FullArchiveGroup ++ ")"
|
|
|
|
preferredContent FullArchiveGroup = lastResort notArchived
|
2013-01-21 08:18:05 +00:00
|
|
|
preferredContent SourceGroup = "not (copies=1)"
|
2013-04-06 22:29:52 +00:00
|
|
|
preferredContent ManualGroup = "present and (" ++ preferredContent ClientGroup ++ ")"
|
2013-04-26 03:44:55 +00:00
|
|
|
preferredContent PublicGroup = "inpreferreddir"
|
2013-03-31 21:10:25 +00:00
|
|
|
preferredContent UnwantedGroup = "exclude=*"
|
2013-04-06 22:29:52 +00:00
|
|
|
|
|
|
|
notArchived :: String
|
|
|
|
notArchived = "not (copies=archive:1 or copies=smallarchive:1)"
|
2013-03-31 23:00:43 +00:00
|
|
|
|
|
|
|
{- Most repositories want any content that is only on untrusted
|
2014-01-21 22:46:39 +00:00
|
|
|
- or dead repositories, or that otherwise does not have enough copies.
|
|
|
|
- Does not look at .gitattributes since that is quite a lot slower.
|
|
|
|
-}
|
2014-01-01 23:58:02 +00:00
|
|
|
lastResort :: String -> PreferredContentExpression
|
2014-01-21 22:46:39 +00:00
|
|
|
lastResort s = "(" ++ s ++ ") or approxlackingcopies=1"
|