Skip to content

Commit 12592ef

Browse files
takluyvergnestor
authored andcommitted
The root directory of the notebook server should never be hidden (#2907)
* The root directory of the notebook server should never be hidden Closes gh-2382 * Test that root dir is not hidden
1 parent 43a9780 commit 12592ef

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

notebook/tests/test_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def test_is_hidden():
6161
os.makedirs(subdir1)
6262
nt.assert_equal(is_hidden(subdir1, root), False)
6363
nt.assert_equal(is_file_hidden(subdir1), False)
64+
6465
subdir2 = os.path.join(root, '.subdir2')
6566
os.makedirs(subdir2)
6667
nt.assert_equal(is_hidden(subdir2, root), True)
67-
nt.assert_equal(is_file_hidden(subdir2), True)
68+
nt.assert_equal(is_file_hidden(subdir2), True)#
69+
# root dir is always visible
70+
nt.assert_equal(is_hidden(subdir2, subdir2), False)
71+
6872
subdir34 = os.path.join(root, 'subdir3', '.subdir4')
6973
os.makedirs(subdir34)
7074
nt.assert_equal(is_hidden(subdir34, root), True)

notebook/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ def is_hidden(abs_path, abs_root=''):
173173
determined by either name starting with '.' or the UF_HIDDEN flag as
174174
reported by stat.
175175
176+
If abs_path is the same directory as abs_root, it will be visible even if
177+
that is a hidden folder. This only checks the visibility of files
178+
and directories *within* abs_root.
179+
176180
Parameters
177181
----------
178182
abs_path : unicode
@@ -181,6 +185,9 @@ def is_hidden(abs_path, abs_root=''):
181185
The absolute path of the root directory in which hidden directories
182186
should be checked for.
183187
"""
188+
if os.path.normpath(abs_path) == os.path.normpath(abs_root):
189+
return False
190+
184191
if is_file_hidden(abs_path):
185192
return True
186193

0 commit comments

Comments
 (0)