Skip to content

Commit

Permalink
Check all file parts for hidden attributes (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
athackst committed Sep 30, 2022
1 parent 52cf937 commit 71b4e09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mkdocs_simple_plugin/semiliterate.py
Expand Up @@ -229,7 +229,7 @@ def write(self, arg: str):
def close(self):
"""Finish the file."""
if self.file_object is not None:
utils.log.debug(
utils.log.info(
" ... extracted %s",
os.path.join(
self.file_directory,
Expand Down
13 changes: 8 additions & 5 deletions mkdocs_simple_plugin/simple.py
Expand Up @@ -147,9 +147,14 @@ def has_hidden_attribute(filepath):
return False

def has_hidden_prefix(filepath):
name = os.path.basename(os.path.abspath(filepath))
return any(name.startswith(pattern)
for pattern in self.hidden_prefix)
parts = filepath.split(os.path.sep)

def hidden_prefix(name):
if name == ".":
return False
return any(name.startswith(pattern)
for pattern in self.hidden_prefix)
return any(hidden_prefix(part) for part in parts)

return has_hidden_prefix(filepath) or has_hidden_attribute(filepath)

Expand Down Expand Up @@ -202,8 +207,6 @@ def try_copy_file(self, from_dir: str, name: str, to_dir: str) -> bool:
new_file = os.path.join(to_dir, name)

if not self.should_copy_file(name):
utils.log.debug(
"mkdocs-simple-plugin: skip copying file %s", original)
return False
try:
os.makedirs(to_dir, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_simple.py
Expand Up @@ -49,6 +49,7 @@ def test_is_hidden(self, os_stat):
self.assertFalse(simple_test.is_hidden('./folder/test.md'))
self.assertTrue(simple_test.is_hidden('__pycache__'))
self.assertTrue(simple_test.is_hidden('.mkdocsignore'))
self.assertTrue(simple_test.is_hidden(".git/objects/34/49807110bdc8"))
# Check hidden file attribute
os_stat.return_value.st_file_attributes = stat.FILE_ATTRIBUTE_HIDDEN
self.assertTrue(simple_test.is_hidden('/test/file'))
Expand Down

0 comments on commit 71b4e09

Please sign in to comment.