Skip to content

Commit 671f8d5

Browse files
authored
Merge pull request #170 from python-discord/files-exclude-hidden
Exclude hidden paths in files output
2 parents 8a85b86 + 9b31db9 commit 671f8d5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

snekbox/memfs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ def files(
138138
"""
139139
count = 0
140140
for file in self.output.rglob(pattern):
141+
# Ignore hidden directories or files
142+
if any(part.startswith(".") for part in file.parts):
143+
log.info(f"Skipping hidden path {file!s}")
144+
continue
145+
141146
if exclude_files and (orig_time := exclude_files.get(file)):
142147
new_time = file.stat().st_mtime
143148
log.info(f"Checking {file.name} ({orig_time=}, {new_time=})")

tests/test_nsjail.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ def test_write_exceed_space(self):
170170
self.assertIn("No space left on device", result.stdout)
171171
self.assertEqual(result.stderr, None)
172172

173+
def test_write_hidden_exclude(self):
174+
"""Hidden paths should be excluded from output."""
175+
code = dedent(
176+
"""
177+
from pathlib import Path
178+
179+
Path("normal").mkdir()
180+
Path("normal/a.txt").write_text("a")
181+
Path("normal/.hidden.txt").write_text("a")
182+
Path(".hidden").mkdir()
183+
Path(".hidden/b.txt").write_text("b")
184+
"""
185+
).strip()
186+
187+
result = self.eval_file(code)
188+
self.assertEqual(result.returncode, 0)
189+
self.assertEqual(len(result.files), 1)
190+
self.assertEqual(result.files[0].content, b"a")
191+
173192
def test_forkbomb_resource_unavailable(self):
174193
code = dedent(
175194
"""

0 commit comments

Comments
 (0)