Skip to content

Commit 348f32f

Browse files
committed
FIX: Check and report mount table parse failures
1 parent e679215 commit 348f32f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

nipype/utils/filemanip.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,25 @@ def _parse_mount_table(exit_code, output):
289289
# <PATH>^^^^ ^^^^^<FSTYPE>
290290
# OSX mount example: /dev/disk2 on / (hfs, local, journaled)
291291
# <PATH>^ ^^^<FSTYPE>
292-
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,]+)(?:, |\)| )')
292+
pattern = re.compile(r'.*? on (/.*?) (?:type |\()([^\s,\)]+)')
293+
294+
# Keep line and match for error reporting (match == None on failure)
295+
# Ignore empty lines
296+
matches = [(l, pattern.match(l))
297+
for l in output.strip().splitlines() if l]
293298

294299
# (path, fstype) tuples, sorted by path length (longest first)
295-
mount_info = sorted((pattern.match(l).groups()
296-
for l in output.splitlines()),
300+
mount_info = sorted((match.groups() for _, match in matches
301+
if match is not None),
297302
key=lambda x: len(x[0]), reverse=True)
298303
cifs_paths = [path for path, fstype in mount_info
299304
if fstype.lower() == 'cifs']
300305

306+
# Report failures as warnings
307+
for line, match in matches:
308+
if match is None:
309+
fmlogger.debug("Cannot parse mount line: '%s'", line)
310+
301311
return [
302312
mount for mount in mount_info
303313
if any(mount[0].startswith(path) for path in cifs_paths)

nipype/utils/tests/test_filemanip.py

Lines changed: 10 additions & 1 deletion
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)