aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Boris Muratov <[email protected]>2023-03-10 14:47:56 +0200
committerGravatar GitHub <[email protected]>2023-03-10 14:47:56 +0200
commit671f8d56c0196a343055487d7ccf15ead5f4f53a (patch)
tree0cabd781771862e300861c55112c2b9a8f73465f
parentMerge pull request #159 from python-discord/bytes-output (diff)
parentAdd unit test for hidden paths exclusion (diff)
Merge pull request #170 from python-discord/files-exclude-hidden
Exclude hidden paths in files output
-rw-r--r--snekbox/memfs.py5
-rw-r--r--tests/test_nsjail.py19
2 files changed, 24 insertions, 0 deletions
diff --git a/snekbox/memfs.py b/snekbox/memfs.py
index f32fed1..ddea9a9 100644
--- a/snekbox/memfs.py
+++ b/snekbox/memfs.py
@@ -138,6 +138,11 @@ class MemFS:
"""
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=})")
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py
index cad79f3..456046b 100644
--- a/tests/test_nsjail.py
+++ b/tests/test_nsjail.py
@@ -170,6 +170,25 @@ class NsJailTests(unittest.TestCase):
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(
"""