From 1e511c5ebf96d2f1a7372c931bfda01cbc314c10 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 16 Aug 2017 18:26:25 +0100 Subject: [PATCH 1/2] Catch OSError when getting file mtime & ctime Closes gh-2757 --- notebook/services/contents/filemanager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/notebook/services/contents/filemanager.py b/notebook/services/contents/filemanager.py index 0f7a0b246..d549966d2 100644 --- a/notebook/services/contents/filemanager.py +++ b/notebook/services/contents/filemanager.py @@ -235,15 +235,18 @@ class FileContentsManager(FileManagerMixin, ContentsManager): info = os.lstat(os_path) try: last_modified = tz.utcfromtimestamp(info.st_mtime) - except ValueError: + except (ValueError, OSError): # Files can rarely have an invalid timestamp # https://github.com/jupyter/notebook/issues/2539 + # https://github.com/jupyter/notebook/issues/2757 # Use the Unix epoch as a fallback so we don't crash. + self.log.warn('Invalid mtime %s for %s', info.st_mtime, os_path) last_modified = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC) try: created = tz.utcfromtimestamp(info.st_ctime) - except ValueError: # See above + except (ValueError, OSError): # See above + self.log.warn('Invalid ctime %s for %s', info.st_ctime, os_path) created = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC) # Create the base model. From 3115f0602feb2c67bf4a67ae48bbe449b32ecfe9 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 17 Aug 2017 11:08:04 +0100 Subject: [PATCH 2/2] deprecated name warn() -> warning() --- notebook/services/contents/filemanager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/services/contents/filemanager.py b/notebook/services/contents/filemanager.py index d549966d2..a5668d44a 100644 --- a/notebook/services/contents/filemanager.py +++ b/notebook/services/contents/filemanager.py @@ -240,13 +240,13 @@ class FileContentsManager(FileManagerMixin, ContentsManager): # https://github.com/jupyter/notebook/issues/2539 # https://github.com/jupyter/notebook/issues/2757 # Use the Unix epoch as a fallback so we don't crash. - self.log.warn('Invalid mtime %s for %s', info.st_mtime, os_path) + self.log.warning('Invalid mtime %s for %s', info.st_mtime, os_path) last_modified = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC) try: created = tz.utcfromtimestamp(info.st_ctime) except (ValueError, OSError): # See above - self.log.warn('Invalid ctime %s for %s', info.st_ctime, os_path) + self.log.warning('Invalid ctime %s for %s', info.st_ctime, os_path) created = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC) # Create the base model.