mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #7471 from terminalmage/issue2828
Fix mtime option in file.find
This commit is contained in:
commit
6eb396d636
@ -491,7 +491,7 @@ def find(path, **kwargs):
|
||||
|
||||
interval::
|
||||
|
||||
[<num>w] [<num>[d]] [<num>h] [<num>m] [<num>s]
|
||||
[<num>w] [<num>d] [<num>h] [<num>m] [<num>s]
|
||||
|
||||
where:
|
||||
w: week
|
||||
|
@ -124,15 +124,16 @@ _FILE_TYPES = {'b': stat.S_IFBLK,
|
||||
stat.S_IFSOCK: 's'}
|
||||
|
||||
_INTERVAL_REGEX = re.compile(r'''
|
||||
^\s*
|
||||
(?: (?P<week> \d+ (?:\.\d*)? ) \s* [wW] )? \s*
|
||||
(?: (?P<day> \d+ (?:\.\d*)? ) \s* [dD]? )? \s*
|
||||
(?: (?P<hour> \d+ (?:\.\d*)? ) \s* [hH] )? \s*
|
||||
(?: (?P<minute> \d+ (?:\.\d*)? ) \s* [mM] )? \s*
|
||||
(?: (?P<second> \d+ (?:\.\d*)? ) \s* [sS] )? \s*
|
||||
$
|
||||
''',
|
||||
flags=re.VERBOSE)
|
||||
^\s*
|
||||
([+-]?)
|
||||
(?: (?P<week> \d+ (?:\.\d*)? ) \s* [wW] )? \s*
|
||||
(?: (?P<day> \d+ (?:\.\d*)? ) \s* [dD] )? \s*
|
||||
(?: (?P<hour> \d+ (?:\.\d*)? ) \s* [hH] )? \s*
|
||||
(?: (?P<minute> \d+ (?:\.\d*)? ) \s* [mM] )? \s*
|
||||
(?: (?P<second> \d+ (?:\.\d*)? ) \s* [sS] )? \s*
|
||||
$
|
||||
''',
|
||||
flags=re.VERBOSE)
|
||||
|
||||
|
||||
def _parse_interval(value):
|
||||
@ -145,7 +146,7 @@ def _parse_interval(value):
|
||||
m = minute
|
||||
s = second
|
||||
'''
|
||||
match = _INTERVAL_REGEX.match(value)
|
||||
match = _INTERVAL_REGEX.match(str(value))
|
||||
if match is None:
|
||||
raise ValueError('invalid time interval: "{0}"'.format(value))
|
||||
|
||||
@ -161,7 +162,7 @@ def _parse_interval(value):
|
||||
if resolution is None:
|
||||
resolution = multiplier
|
||||
|
||||
return result, resolution
|
||||
return result, resolution, match.group(1)
|
||||
|
||||
|
||||
def _parse_size(value):
|
||||
@ -395,14 +396,18 @@ class MtimeOption(Option):
|
||||
Whitespace is ignored in the value.
|
||||
'''
|
||||
def __init__(self, key, value):
|
||||
secs, resolution = _parse_interval(value)
|
||||
self.min_time = time.time() - int(secs / resolution) * resolution
|
||||
secs, resolution, modifier = _parse_interval(value)
|
||||
self.mtime = time.time() - int(secs / resolution) * resolution
|
||||
self.modifier = modifier
|
||||
|
||||
def requires(self):
|
||||
return _REQUIRES_STAT
|
||||
|
||||
def match(self, dirname, filename, fstat):
|
||||
return fstat[stat.ST_MTIME] >= self.min_time
|
||||
if self.modifier == '-':
|
||||
return fstat[stat.ST_MTIME] >= self.mtime
|
||||
else:
|
||||
return fstat[stat.ST_MTIME] <= self.mtime
|
||||
|
||||
|
||||
class GrepOption(Option):
|
||||
@ -515,7 +520,7 @@ class Finder(object):
|
||||
if key.startswith('_'):
|
||||
# this is a passthrough object, continue
|
||||
continue
|
||||
if value is None or len(value) == 0:
|
||||
if value is None or len(str(value)) == 0:
|
||||
raise ValueError('missing value for "{0}" option'.format(key))
|
||||
try:
|
||||
obj = globals()[key.title() + "Option"](key, value)
|
||||
|
Loading…
Reference in New Issue
Block a user