diff --git a/notebook/tests/test_utils.py b/notebook/tests/test_utils.py index 8922beb389..2033209a34 100644 --- a/notebook/tests/test_utils.py +++ b/notebook/tests/test_utils.py @@ -61,10 +61,14 @@ def test_is_hidden(): os.makedirs(subdir1) nt.assert_equal(is_hidden(subdir1, root), False) nt.assert_equal(is_file_hidden(subdir1), False) + subdir2 = os.path.join(root, '.subdir2') os.makedirs(subdir2) nt.assert_equal(is_hidden(subdir2, root), True) - nt.assert_equal(is_file_hidden(subdir2), True) + nt.assert_equal(is_file_hidden(subdir2), True)# + # root dir is always visible + nt.assert_equal(is_hidden(subdir2, subdir2), False) + subdir34 = os.path.join(root, 'subdir3', '.subdir4') os.makedirs(subdir34) nt.assert_equal(is_hidden(subdir34, root), True) diff --git a/notebook/utils.py b/notebook/utils.py index c0d85f6b28..ea4a1a5ed5 100644 --- a/notebook/utils.py +++ b/notebook/utils.py @@ -173,6 +173,10 @@ def is_hidden(abs_path, abs_root=''): determined by either name starting with '.' or the UF_HIDDEN flag as reported by stat. + If abs_path is the same directory as abs_root, it will be visible even if + that is a hidden folder. This only checks the visibility of files + and directories *within* abs_root. + Parameters ---------- abs_path : unicode @@ -181,6 +185,9 @@ def is_hidden(abs_path, abs_root=''): The absolute path of the root directory in which hidden directories should be checked for. """ + if os.path.normpath(abs_path) == os.path.normpath(abs_root): + return False + if is_file_hidden(abs_path): return True