Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.find module: fix handling of broken symlinks #34239

Merged
merged 1 commit into from
Jun 23, 2016
Merged

file.find module: fix handling of broken symlinks #34239

merged 1 commit into from
Jun 23, 2016

Conversation

vutny
Copy link
Contributor

@vutny vutny commented Jun 23, 2016

What does this PR do?

Fixes salt.modules.file.find function to handle broken symlinks.

Use Case

I would like get all symlinks in the directory, some of them are eventually broken (point to non-existent files).

Setup is very simple: standalone Salt Minion 2016.3.1 and following directory layout with broken symlink:

cd /root
rm -f test*
ln -sf test test2

If I query the files just by name it works:

salt-call --local file.find /root name='test*'
local:
    - /root/test2

But...

Previous Behavior

If I would like to get only symlinks among all the files it fails:

salt-call --local file.find /root name='test*' type=l 
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
OSError: [Errno 2] No such file or directory: '/root/test2'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 345, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 197, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 694, in find
    ret = [item for i in [finder.find(p) for p in glob.glob(os.path.expanduser(path))] for item in i]
  File "/usr/lib/python2.7/dist-packages/salt/utils/find.py", line 643, in find
    fstat = os.stat(fullpath)
OSError: [Errno 2] No such file or directory: '/root/test2'
Traceback (most recent call last):
  File "/usr/bin/salt-call", line 11, in <module>
    salt_call()
  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 345, in salt_call
    client.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 134, in run
    ret = self.call()
  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 197, in call
    ret['return'] = func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 694, in find
    ret = [item for i in [finder.find(p) for p in glob.glob(os.path.expanduser(path))] for item in i]
  File "/usr/lib/python2.7/dist-packages/salt/utils/find.py", line 643, in find
    fstat = os.stat(fullpath)
OSError: [Errno 2] No such file or directory: '/root/test2'

New Behavior

My PR fixes this and allows to delete such files:

salt-call --local file.find /root name='test*' type=l
local:
    - /root/test2
salt-call --local file.find /root name='test*' delete=l
local:
    - /root/test2

Tests written?

No

@cachedout cachedout merged commit f74f176 into saltstack:2016.3 Jun 23, 2016
@vutny vutny deleted the file-find-broken-symlinks branch June 24, 2016 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants