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:
David Wittman 2015-12-02 11:27:44 -06:00 committed by Matt Clay
parent 895179929c
commit 85f6c26dff

View file

@ -66,7 +66,7 @@ options:
required: false
description:
- Type of file to select
choices: [ "file", "directory" ]
choices: [ "file", "directory", "link" ]
default: "file"
recurse:
required: false
@ -275,7 +275,7 @@ def main():
paths = dict(required=True, aliases=['name','path'], type='list'),
patterns = dict(default=['*'], type='list', aliases=['pattern']),
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_stamp = dict(default="mtime", choices=['atime','mtime','ctime'], type='str'),
size = dict(default=None, type='str'),
@ -331,7 +331,7 @@ def main():
continue
try:
st = os.stat(fsname)
st = os.lstat(fsname)
except:
msg+="%s was skipped as it does not seem to be a valid file or it cannot be accessed\n" % fsname
continue
@ -354,6 +354,11 @@ def main():
r['checksum'] = module.sha1(fsname)
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']:
break
else: