Added --smallerthan and --largerthan limits
This commit is contained in:
parent
71fd18a97f
commit
7cd81bd978
6 changed files with 38 additions and 9 deletions
|
@ -147,6 +147,10 @@ options = Option.common ++
|
||||||
"skip files with fewer copies"
|
"skip files with fewer copies"
|
||||||
, Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName)
|
, Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName)
|
||||||
"skip files not using a key-value backend"
|
"skip files not using a key-value backend"
|
||||||
|
, Option [] ["largerthan"] (ReqArg Limit.addLargerThan paramName)
|
||||||
|
"skip files larger than a size"
|
||||||
|
, Option [] ["smallerthan"] (ReqArg Limit.addSmallerThan paramName)
|
||||||
|
"skip files smaller than a size"
|
||||||
, Option ['T'] ["time-limit"] (ReqArg Limit.addTimeLimit paramTime)
|
, Option ['T'] ["time-limit"] (ReqArg Limit.addTimeLimit paramTime)
|
||||||
"stop after the specified amount of time"
|
"stop after the specified amount of time"
|
||||||
] ++ Option.matcher
|
] ++ Option.matcher
|
||||||
|
|
17
Limit.hs
17
Limit.hs
|
@ -21,8 +21,10 @@ import Annex.Content
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
import Types.TrustLevel
|
import Types.TrustLevel
|
||||||
|
import Types.Key
|
||||||
import Logs.Group
|
import Logs.Group
|
||||||
import Utility.HumanTime
|
import Utility.HumanTime
|
||||||
|
import Utility.DataUnits
|
||||||
|
|
||||||
type MatchFiles = AssumeNotPresent -> FilePath -> Annex Bool
|
type MatchFiles = AssumeNotPresent -> FilePath -> Annex Bool
|
||||||
type MkLimit = String -> Either String MatchFiles
|
type MkLimit = String -> Either String MatchFiles
|
||||||
|
@ -143,6 +145,21 @@ limitInBackend name = Right $ const $ Backend.lookupFile >=> check
|
||||||
wanted = Backend.lookupBackendName name
|
wanted = Backend.lookupBackendName name
|
||||||
check = return . maybe False ((==) wanted . snd)
|
check = return . maybe False ((==) wanted . snd)
|
||||||
|
|
||||||
|
{- Adds a limit to skip files that are too large or too small -}
|
||||||
|
addLargerThan :: String -> Annex ()
|
||||||
|
addLargerThan = addLimit . limitSize (>)
|
||||||
|
|
||||||
|
addSmallerThan :: String -> Annex ()
|
||||||
|
addSmallerThan = addLimit . limitSize (<)
|
||||||
|
|
||||||
|
limitSize :: (Maybe Integer -> Maybe Integer -> Bool) -> MkLimit
|
||||||
|
limitSize vs s = case readSize dataUnits s of
|
||||||
|
Nothing -> Left "bad size"
|
||||||
|
Just sz -> Right $ const $ Backend.lookupFile >=> check sz
|
||||||
|
where
|
||||||
|
check _ Nothing = return False
|
||||||
|
check sz (Just (key, _)) = return $ keySize key `vs` Just sz
|
||||||
|
|
||||||
addTimeLimit :: String -> Annex ()
|
addTimeLimit :: String -> Annex ()
|
||||||
addTimeLimit s = do
|
addTimeLimit s = do
|
||||||
let seconds = fromMaybe (error "bad time-limit") $ parseDuration s
|
let seconds = fromMaybe (error "bad time-limit") $ parseDuration s
|
||||||
|
|
|
@ -21,7 +21,7 @@ import Common.Annex
|
||||||
import qualified Annex.Branch
|
import qualified Annex.Branch
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Logs.UUIDBased
|
import Logs.UUIDBased
|
||||||
import Limit (MatchFiles, AssumeNotPresent, limitInclude, limitExclude, limitIn, limitCopies, limitInBackend)
|
import Limit
|
||||||
import qualified Utility.Matcher
|
import qualified Utility.Matcher
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
import Git.FilePath
|
import Git.FilePath
|
||||||
|
@ -96,6 +96,8 @@ parseToken t
|
||||||
, ("in", limitIn)
|
, ("in", limitIn)
|
||||||
, ("copies", limitCopies)
|
, ("copies", limitCopies)
|
||||||
, ("backend", limitInBackend)
|
, ("backend", limitInBackend)
|
||||||
|
, ("largerthan", limitSize (>))
|
||||||
|
, ("smallerthan", limitSize (<))
|
||||||
]
|
]
|
||||||
use a = Utility.Matcher.Operation <$> a v
|
use a = Utility.Matcher.Operation <$> a v
|
||||||
|
|
||||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -12,7 +12,8 @@ git-annex (3.20121002) UNRELEASED; urgency=low
|
||||||
* get --auto, copy --auto: If the local repository has preferred content
|
* get --auto, copy --auto: If the local repository has preferred content
|
||||||
configured, only get that content.
|
configured, only get that content.
|
||||||
* drop --auto: If the local repository has preferred content configured,
|
* drop --auto: If the local repository has preferred content configured,
|
||||||
drop content that is not preferred, if numcopies allows.
|
drop content that is not preferred, when numcopies allows.
|
||||||
|
* Added --smallerthan and --largerthan limits.
|
||||||
* Only build-depend on libghc-clientsession-dev on arches that will have
|
* Only build-depend on libghc-clientsession-dev on arches that will have
|
||||||
the webapp.
|
the webapp.
|
||||||
* uninit: Unset annex.version. Closes: #689852
|
* uninit: Unset annex.version. Closes: #689852
|
||||||
|
|
|
@ -8,9 +8,9 @@ But often the remote is just a removable drive or a cloud remote,
|
||||||
that has a limited size. This page is about making the assistant do
|
that has a limited size. This page is about making the assistant do
|
||||||
something smart with such remotes.
|
something smart with such remotes.
|
||||||
|
|
||||||
## specifying what data belongs on a remote
|
## specifying what data a remote prefers to contain **done**
|
||||||
|
|
||||||
Imagine a per-remote `annex-accept` setting, that matches things that
|
Imagine a per-remote preferred content setting, that matches things that
|
||||||
should be stored on the remote.
|
should be stored on the remote.
|
||||||
|
|
||||||
For example, a MP3 player might use:
|
For example, a MP3 player might use:
|
||||||
|
@ -23,14 +23,10 @@ A USB drive that is carried between three laptops and used to sync data
|
||||||
between them might use: `not (in=laptop1 and in=laptop2 and in=laptop3)`
|
between them might use: `not (in=laptop1 and in=laptop2 and in=laptop3)`
|
||||||
|
|
||||||
In this case, transferring data from the usb repo should
|
In this case, transferring data from the usb repo should
|
||||||
check if `annex-accept` then rejects the data, and if so, drop it
|
check if preferred content settings rejects the data, and if so, drop it
|
||||||
from the repo. So once all three laptops have the data, it is
|
from the repo. So once all three laptops have the data, it is
|
||||||
pruned from the transfer drive.
|
pruned from the transfer drive.
|
||||||
|
|
||||||
It may make sense to have annex-accept info also be stored in the git-annex
|
|
||||||
branch, for settings that should apply to a repo globally. Does it make
|
|
||||||
sense to have local configuration too?
|
|
||||||
|
|
||||||
## repo groups
|
## repo groups
|
||||||
|
|
||||||
Seems like git-annex needs a way to know the groups of repos. Some
|
Seems like git-annex needs a way to know the groups of repos. Some
|
||||||
|
|
|
@ -643,6 +643,15 @@ file contents are present at either of two repositories.
|
||||||
Matches only files whose content is stored using the specified key-value
|
Matches only files whose content is stored using the specified key-value
|
||||||
backend.
|
backend.
|
||||||
|
|
||||||
|
* --smallerthan=size
|
||||||
|
* --largerthan=size
|
||||||
|
|
||||||
|
Matches only files whose content is smaller than, or larger than the
|
||||||
|
specified size.
|
||||||
|
|
||||||
|
The size can be specified with any commonly used units, for example,
|
||||||
|
"0.5 gb" or "100 KiloBytes"
|
||||||
|
|
||||||
* --not
|
* --not
|
||||||
|
|
||||||
Inverts the next file matching option. For example, to only act on
|
Inverts the next file matching option. For example, to only act on
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue