Skip to content

Commit

Permalink
Merge pull request #170 from python-discord/files-exclude-hidden
Browse files Browse the repository at this point in the history
Exclude hidden paths in files output
  • Loading branch information
mbaruh authored Mar 10, 2023
2 parents 8a85b86 + 9b31db9 commit 671f8d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions snekbox/memfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def files(
"""
count = 0
for file in self.output.rglob(pattern):
# Ignore hidden directories or files
if any(part.startswith(".") for part in file.parts):
log.info(f"Skipping hidden path {file!s}")
continue

if exclude_files and (orig_time := exclude_files.get(file)):
new_time = file.stat().st_mtime
log.info(f"Checking {file.name} ({orig_time=}, {new_time=})")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_nsjail.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ def test_write_exceed_space(self):
self.assertIn("No space left on device", result.stdout)
self.assertEqual(result.stderr, None)

def test_write_hidden_exclude(self):
"""Hidden paths should be excluded from output."""
code = dedent(
"""
from pathlib import Path
Path("normal").mkdir()
Path("normal/a.txt").write_text("a")
Path("normal/.hidden.txt").write_text("a")
Path(".hidden").mkdir()
Path(".hidden/b.txt").write_text("b")
"""
).strip()

result = self.eval_file(code)
self.assertEqual(result.returncode, 0)
self.assertEqual(len(result.files), 1)
self.assertEqual(result.files[0].content, b"a")

def test_forkbomb_resource_unavailable(self):
code = dedent(
"""
Expand Down

0 comments on commit 671f8d5

Please sign in to comment.