diff --git a/sandbox/default.yaml b/sandbox/default.yaml index f5c0948..9012fd5 100644 --- a/sandbox/default.yaml +++ b/sandbox/default.yaml @@ -27,6 +27,7 @@ filesystem: - "{XDG_CONFIG_HOME}/gh" - "{XDG_DATA_HOME}/gh/extensions" - "/dev" + - "{HOME}/img" rw: - "{OLLIE_MEMORY_PATH}" - "{OLLIE_PLAN_PATH}" @@ -75,6 +76,7 @@ filesystem: - "/dev/random" - "/dev/null" - "/dev/fuse" + - "{PCFS}" rox: - "/usr" - "/lib" @@ -135,5 +137,6 @@ env: - EDITOR - GIT_SEQUENCE_EDITOR - SUPERPOWERD_SESSION_TOKEN + - PCFS network: unrestricted: true diff --git a/tools/file_read b/tools/file_read index 533230e..cd8d92e 100755 --- a/tools/file_read +++ b/tools/file_read @@ -5,10 +5,10 @@ import sys import os +from itertools import islice MAX_LINES = 2000 MAX_LINE_LEN = 2000 -MAX_SIZE = 8 * 1024 * 1024 if len(sys.argv) < 2: print("usage: file_read [start] [end]") @@ -30,24 +30,21 @@ if not os.path.isfile(file_path): print(f"error: not a regular file: {file_path}") sys.exit(1) -size = os.path.getsize(file_path) -if size > MAX_SIZE: - print(f"error: file too large ({size} bytes, max {MAX_SIZE})") - sys.exit(1) - with open(file_path, 'rb') as f: if b'\x00' in f.read(8192): print("(binary file)") sys.exit(0) -with open(file_path, 'r', errors='replace') as f: - all_lines = f.readlines() - -total = len(all_lines) start = max(1, start) -end = min(end, total) if end is not None else min(total, start + MAX_LINES - 1) +if end is None: + end = start + MAX_LINES - 1 -segment_lines = all_lines[start - 1:end] +with open(file_path, 'r', errors='replace') as f: + # Skip lines before start + for _ in islice(f, start - 1): + pass + # Read only the lines we need + segment_lines = list(islice(f, end - start + 1)) if not segment_lines: print("(empty file)" if start == 1 else "(no lines in range)")