Add 'link' file_type to find_module
- Adds the 'link' file_type for finding symbolic or hard links - Use `os.lstat` instead of `os.stat` to prevent the following of links when statting the file.
This commit is contained in:
parent
895179929c
commit
85f6c26dff
1 changed files with 8 additions and 3 deletions
|
@ -66,7 +66,7 @@ options:
|
||||||
required: false
|
required: false
|
||||||
description:
|
description:
|
||||||
- Type of file to select
|
- Type of file to select
|
||||||
choices: [ "file", "directory" ]
|
choices: [ "file", "directory", "link" ]
|
||||||
default: "file"
|
default: "file"
|
||||||
recurse:
|
recurse:
|
||||||
required: false
|
required: false
|
||||||
|
@ -275,7 +275,7 @@ def main():
|
||||||
paths = dict(required=True, aliases=['name','path'], type='list'),
|
paths = dict(required=True, aliases=['name','path'], type='list'),
|
||||||
patterns = dict(default=['*'], type='list', aliases=['pattern']),
|
patterns = dict(default=['*'], type='list', aliases=['pattern']),
|
||||||
contains = dict(default=None, type='str'),
|
contains = dict(default=None, type='str'),
|
||||||
file_type = dict(default="file", choices=['file', 'directory'], type='str'),
|
file_type = dict(default="file", choices=['file', 'directory', 'link'], type='str'),
|
||||||
age = dict(default=None, type='str'),
|
age = dict(default=None, type='str'),
|
||||||
age_stamp = dict(default="mtime", choices=['atime','mtime','ctime'], type='str'),
|
age_stamp = dict(default="mtime", choices=['atime','mtime','ctime'], type='str'),
|
||||||
size = dict(default=None, type='str'),
|
size = dict(default=None, type='str'),
|
||||||
|
@ -331,7 +331,7 @@ def main():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
st = os.stat(fsname)
|
st = os.lstat(fsname)
|
||||||
except:
|
except:
|
||||||
msg+="%s was skipped as it does not seem to be a valid file or it cannot be accessed\n" % fsname
|
msg+="%s was skipped as it does not seem to be a valid file or it cannot be accessed\n" % fsname
|
||||||
continue
|
continue
|
||||||
|
@ -354,6 +354,11 @@ def main():
|
||||||
r['checksum'] = module.sha1(fsname)
|
r['checksum'] = module.sha1(fsname)
|
||||||
filelist.append(r)
|
filelist.append(r)
|
||||||
|
|
||||||
|
elif stat.S_ISLNK(st.st_mode) and params['file_type'] == 'link':
|
||||||
|
if pfilter(fsobj, params['patterns'], params['use_regex']) and agefilter(st, now, age, params['age_stamp']):
|
||||||
|
r.update(statinfo(st))
|
||||||
|
filelist.append(r)
|
||||||
|
|
||||||
if not params['recurse']:
|
if not params['recurse']:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue