Skip to content
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

Fix for recursive symlink issue #4669 #4670

Merged
merged 7 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
18 changes: 12 additions & 6 deletions notebook/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,18 @@ def _dir_model(self, path, content=True):
self.log.debug("%s not a regular file", os_path)
continue

if self.should_list(name):
if self.allow_hidden or not is_file_hidden(os_path, stat_res=st):
contents.append(
self.get(path='%s/%s' % (path, name), content=False)
)

try:
if self.should_list(name):
if self.allow_hidden or not is_file_hidden(os_path, stat_res=st):
contents.append(
self.get(path='%s/%s' % (path, name), content=False)
)
except OSError as e:
# Ignore recursive links and move on
if e.errno==errno.ELOOP:
continue
else:
raise e
model['format'] = 'json'

return model
Expand Down
20 changes: 20 additions & 0 deletions notebook/services/contents/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ def test_bad_symlink(self):
# broken symlinks should still be shown in the contents manager
self.assertTrue('bad symlink' in contents)

@dec.skipif(sys.platform == 'win32' and sys.version_info[0] < 3)
def test_recursive_symlink(self):
with TemporaryDirectory() as td:
cm = FileContentsManager(root_dir=td)
path = 'test recursive symlink'
_make_dir(cm, path)
os_path = cm._get_os_path(path)
os.symlink("recursive", os.path.join(os_path, "recursive"))
file_model = cm.new_untitled(path=path, ext='.txt')

model = cm.get(path)

contents = {
content['name']: content for content in model['content']
}
self.assertTrue('untitled.txt' in contents)
self.assertEqual(contents['untitled.txt'], file_model)
# recusrive symlinks should not be shown in the contents manager
self.assertFalse('recusrive' in contents)
Copy link
Member

Choose a reason for hiding this comment

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

Spelling of 'recursive'.

Also, we should use the assertIn and assertNotIn methods rather than assertTrue and assertFalse. The more specific methods give more useful messages when things fail.


@dec.skipif(sys.platform == 'win32' and sys.version_info[0] < 3)
def test_good_symlink(self):
with TemporaryDirectory() as td:
Expand Down