Skip to content

FIX: Check and report mount table parsing failures #2476

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

Merged
merged 2 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def fname_presuffix(fname, prefix='', suffix='', newpath=None, use_ext=True):
'/tmp/prefoopost.nii.gz'

>>> from nipype.interfaces.base import Undefined
>>> fname_presuffix(fname, 'pre', 'post', Undefined) == fname_presuffix(fname, 'pre', 'post')
>>> fname_presuffix(fname, 'pre', 'post', Undefined) == \
fname_presuffix(fname, 'pre', 'post')
True

"""
Expand Down Expand Up @@ -289,15 +290,25 @@ def _parse_mount_table(exit_code, output):
# <PATH>^^^^ ^^^^^<FSTYPE>
# OSX mount example: /dev/disk2 on / (hfs, local, journaled)
# <PATH>^ ^^^<FSTYPE>
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,]+)(?:, |\)| )')
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,\)]+)')

# Keep line and match for error reporting (match == None on failure)
# Ignore empty lines
matches = [(l, pattern.match(l))
for l in output.strip().splitlines() if l]

# (path, fstype) tuples, sorted by path length (longest first)
mount_info = sorted((pattern.match(l).groups()
for l in output.splitlines()),
mount_info = sorted((match.groups() for _, match in matches
if match is not None),
key=lambda x: len(x[0]), reverse=True)
cifs_paths = [path for path, fstype in mount_info
if fstype.lower() == 'cifs']

# Report failures as warnings
for line, match in matches:
if match is None:
fmlogger.debug("Cannot parse mount line: '%s'", line)

return [
mount for mount in mount_info
if any(mount[0].startswith(path) for path in cifs_paths)
Expand Down
11 changes: 10 additions & 1 deletion nipype/utils/tests/test_filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,16 @@ def test_related_files(file, length, expected_files):
tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,size=65536k,mode=755)
tmpfs on /proc/scsi type tmpfs (ro,relatime)
tmpfs on /sys/firmware type tmpfs (ro,relatime)
''', 0, [('/data', 'cifs')])
''', 0, [('/data', 'cifs')]),
# From @yarikoptic - added blank lines to test for resilience
(r'''/proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)

devpts on /dev/ptmx type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)

''', 0, []),
)


Expand Down