Skip to content

Unable to handle fstat exceptions when using fs.walk.info #288

Open
@jjmontesl

Description

@jjmontesl

I'm using the following code to walk a filesystem:

for (path, info) in remote_fs.walk.info(namespaces=['details']):

It contains a broken symbolic link, and thus fstat() fails, and interrupts the walk process with the following exception:

Traceback (most recent call last):
  File "/home/jjmontes/git/sitetool/env/lib/python3.6/site-packages/fs-2.4.5-py3.6.egg/fs/osfs.py", line 492, in _scandir
    stat_result = dir_entry.stat()
FileNotFoundError: [Errno 2] No such file or directory: b'/tmp/cubesviewer/as'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jjmontes/git/sitetool/env/bin/sit", line 11, in <module>
    load_entry_point('sittool', 'console_scripts', 'sit')()
  File "/home/jjmontes/git/sitetool/sitetool/core/bootstrap.py", line 166, in main
    bootstrap.main()  # sys.argv[1:]
  File "/home/jjmontes/git/sitetool/sitetool/core/bootstrap.py", line 152, in main
    st.command.run()
  File "/home/jjmontes/git/sitetool/sitetool/sites.py", line 229, in run
    size_data = self.ctx.get('sites').calculate_site_size(site)
  File "/home/jjmontes/git/sitetool/sitetool/sites.py", line 154, in calculate_site_size
    files = site.comp('files').file_list('')
  File "/home/jjmontes/git/sitetool/sitetool/files/fs.py", line 48, in file_list
    for (path, info) in remote_fs.walk.info(namespaces=['details']):
  File "/home/jjmontes/git/sitetool/env/lib/python3.6/site-packages/fs-2.4.5-py3.6.egg/fs/walk.py", line 405, in info
    for _path, info in _walk:
  File "/home/jjmontes/git/sitetool/env/lib/python3.6/site-packages/fs-2.4.5-py3.6.egg/fs/walk.py", line 433, in _walk_breadth
    for info in _scan(fs, dir_path, namespaces=namespaces):
  File "/home/jjmontes/git/sitetool/env/lib/python3.6/site-packages/fs-2.4.5-py3.6.egg/fs/walk.py", line 298, in _scan
    six.reraise(type(error), error)
  File "/home/jjmontes/git/sitetool/env/lib/python3.6/site-packages/six-1.12.0-py3.6.egg/six.py", line 692, in reraise
    raise value.with_traceback(tb)
fs.errors.ResourceNotFound: resource '/' not found

Python os.walk provides an onerror attribute to handle this situation. Is there as similar option for Filesystem? I'm facing a case where I want to report these errors but otherwise continue the operation.

I can workaround this by removing the 'details' namespace and calling remote_fs.getinfo() myself but I fear that I might be incurring in a performance penalty if doing so.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions