Skip to content

ENH: Disable symlinks on CIFS filesystems #1941

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 5 commits into from
Apr 9, 2017
Merged
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import sys
import pickle
import subprocess
import gzip
import hashlib
from hashlib import md5
Expand Down Expand Up @@ -237,6 +238,30 @@ def hash_timestamp(afile):
return md5hex


def _on_cifs(fname):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it public - could be useful in other places

""" Checks whether a PATH is on a CIFS filesystem mounted in a POSIX
host (i.e., has the "mount" command).

CIFS shares are how Docker mounts Windows host directories into containers.
CIFS has partial support for symlinks that can break, causing misleading
errors, so this test is used to disable them on such systems.
"""
exit_code, output = subprocess.getstatusoutput("mount")
# Not POSIX
if exit_code != 0:
return False

# (path, fstype) tuples, sorted by path length (longest first)
paths_types = sorted((line.split()[2:5:2] for line in output.splitlines()),
key=lambda x: len(x[0]),
reverse=True)
# Only the first match counts
for fspath, fstype in paths_types:
if fname.startswith(fspath):
return fstype == 'cifs'
return False


def copyfile(originalfile, newfile, copy=False, create_new=False,
hashmethod=None, use_hardlink=False,
copy_related_files=True):
Expand Down Expand Up @@ -288,6 +313,10 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
if hashmethod is None:
hashmethod = config.get('execution', 'hash_method').lower()

# Don't try creating symlinks on CIFS
if _on_cifs(newfile):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For performance reasons, I would only run this check if we are about to make a symlink.

copy = True

# Existing file
# -------------
# Options:
Expand Down