From 1975bf830fe5db6adeba3e46108005effa6cec6d Mon Sep 17 00:00:00 2001 From: dhirschf Date: Mon, 19 Jun 2017 20:25:24 +1000 Subject: [PATCH] Addressed review comments --- notebook/services/contents/filemanager.py | 8 ++++---- notebook/utils.py | 11 ++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/notebook/services/contents/filemanager.py b/notebook/services/contents/filemanager.py index ee6036e4a..34ca92386 100644 --- a/notebook/services/contents/filemanager.py +++ b/notebook/services/contents/filemanager.py @@ -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) diff --git a/notebook/utils.py b/notebook/utils.py index 27c54b87d..c0d85f6b2 100644 --- a/notebook/utils.py +++ b/notebook/utils.py @@ -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: