Addressed review comments

pull/2574/head
dhirschf 9 years ago
parent 6bb89b717a
commit 1975bf830f

@ -19,7 +19,7 @@ from tornado import web
from .filecheckpoints import FileCheckpoints
from .fileio import FileManagerMixin
from .manager import ContentsManager
from ...utils import f_stat, WINDOWS_CONTAINER, exists
from ...utils import exists
from ipython_genutils.importstring import import_item
from traitlets import Any, Unicode, Bool, TraitError, observe, default, validate
@ -227,7 +227,7 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
def _base_model(self, path):
"""Build the common base of a contents model"""
os_path = self._get_os_path(path)
info = f_stat(os_path)
info = os.lstat(os_path)
last_modified = tz.utcfromtimestamp(info.st_mtime)
created = tz.utcfromtimestamp(info.st_ctime)
# Create the base model.
@ -277,7 +277,7 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
continue
try:
st = f_stat(os_path)
st = os.lstat(os_path)
except OSError as e:
# skip over broken symlinks in listing
if e.errno == errno.ENOENT:
@ -286,7 +286,7 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
self.log.warning("Error stat-ing %s: %s", os_path, e)
continue
if (not WINDOWS_CONTAINER
if (not stat.S_ISLNK(st.st_mode)
and not stat.S_ISREG(st.st_mode)
and not stat.S_ISDIR(st.st_mode)):
self.log.debug("%s not a regular file", os_path)

@ -24,20 +24,13 @@ from ipython_genutils import py3compat
# It is used by BSD to indicate hidden files.
UF_HIDDEN = getattr(stat, 'UF_HIDDEN', 32768)
# Replace `os.stat` which can't stat a host mapped volume from inside a Windows Container.
WINDOWS_CONTAINER = sys.platform == 'win32' and os.environ.get('USERNAME') == 'ContainerAdministrator'
if WINDOWS_CONTAINER:
f_stat = os.lstat
else:
f_stat = os.stat
def exists(path):
"""Replacement for `os.path.exists` which works for host mapped volumes
on Windows containers
"""
try:
f_stat(path)
os.lstat(path)
except OSError:
return False
return True
@ -206,7 +199,7 @@ def is_hidden(abs_path, abs_root=''):
continue
try:
# may fail on Windows junctions
st = f_stat(path)
st = os.lstat(path)
except OSError:
return True
if getattr(st, 'st_flags', 0) & UF_HIDDEN:

Loading…
Cancel
Save