Skip to content

Commit 88dbce1

Browse files
authored
Merge pull request #2476 from effigies/fix/mount_table_parse
FIX: Check and report mount table parsing failures
2 parents 404cab6 + b8deba0 commit 88dbce1

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

nipype/utils/filemanip.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ def fname_presuffix(fname, prefix='', suffix='', newpath=None, use_ext=True):
177177
'/tmp/prefoopost.nii.gz'
178178
179179
>>> from nipype.interfaces.base import Undefined
180-
>>> fname_presuffix(fname, 'pre', 'post', Undefined) == fname_presuffix(fname, 'pre', 'post')
180+
>>> fname_presuffix(fname, 'pre', 'post', Undefined) == \
181+
fname_presuffix(fname, 'pre', 'post')
181182
True
182183
183184
"""
@@ -281,15 +282,25 @@ def _parse_mount_table(exit_code, output):
281282
# <PATH>^^^^ ^^^^^<FSTYPE>
282283
# OSX mount example: /dev/disk2 on / (hfs, local, journaled)
283284
# <PATH>^ ^^^<FSTYPE>
284-
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,]+)(?:, |\)| )')
285+
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,\)]+)')
286+
287+
# Keep line and match for error reporting (match == None on failure)
288+
# Ignore empty lines
289+
matches = [(l, pattern.match(l))
290+
for l in output.strip().splitlines() if l]
285291

286292
# (path, fstype) tuples, sorted by path length (longest first)
287-
mount_info = sorted((pattern.match(l).groups()
288-
for l in output.splitlines()),
293+
mount_info = sorted((match.groups() for _, match in matches
294+
if match is not None),
289295
key=lambda x: len(x[0]), reverse=True)
290296
cifs_paths = [path for path, fstype in mount_info
291297
if fstype.lower() == 'cifs']
292298

299+
# Report failures as warnings
300+
for line, match in matches:
301+
if match is None:
302+
fmlogger.debug("Cannot parse mount line: '%s'", line)
303+
293304
return [
294305
mount for mount in mount_info
295306
if any(mount[0].startswith(path) for path in cifs_paths)

nipype/utils/tests/test_filemanip.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,16 @@ def test_related_files(file, length, expected_files):
451451
tmpfs on /proc/sched_debug type tmpfs (rw,nosuid,size=65536k,mode=755)
452452
tmpfs on /proc/scsi type tmpfs (ro,relatime)
453453
tmpfs on /sys/firmware type tmpfs (ro,relatime)
454-
''', 0, [('/data', 'cifs')])
454+
''', 0, [('/data', 'cifs')]),
455+
# From @yarikoptic - added blank lines to test for resilience
456+
(r'''/proc on /proc type proc (rw,relatime)
457+
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
458+
tmpfs on /dev/shm type tmpfs (rw,relatime)
459+
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
460+
461+
devpts on /dev/ptmx type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
462+
463+
''', 0, []),
455464
)
456465

457466

0 commit comments

Comments
 (0)