diff --git a/codebasin/__init__.py b/codebasin/__init__.py index c1bd884..909dc76 100644 --- a/codebasin/__init__.py +++ b/codebasin/__init__.py @@ -191,7 +191,7 @@ def from_file(cls, filename: str | os.PathLike[str]): ------- A CompilationDatbase corresponding to the provided JSON file. """ - with codebasin.util.safe_open_read_nofollow(filename, "r") as f: + with open(filename) as f: db = codebasin.util._load_json(f, schema_name="compiledb") return CompilationDatabase.from_json(db) diff --git a/codebasin/__main__.py b/codebasin/__main__.py index 62ed1f4..9cb0d95 100755 --- a/codebasin/__main__.py +++ b/codebasin/__main__.py @@ -283,7 +283,7 @@ def main(): if not os.path.splitext(path)[1] == ".toml": raise RuntimeError(f"Analysis file {path} must end in .toml.") - with util.safe_open_read_nofollow(path, "rb") as f: + with open(path, "rb") as f: try: analysis_toml = util._load_toml(f, "analysis") except BaseException: diff --git a/codebasin/config.py b/codebasin/config.py index 04b0883..38c8c4a 100644 --- a/codebasin/config.py +++ b/codebasin/config.py @@ -82,7 +82,7 @@ def load_importcfg(): path = ".cbi/config" if os.path.exists(path): log.info(f"Found configuration file at {path}") - with util.safe_open_read_nofollow(path, "rb") as f: + with open(path, "rb") as f: try: _importcfg_toml = util._load_toml(f, "cbiconfig") for name, compiler in _importcfg_toml["compiler"].items(): diff --git a/codebasin/file_parser.py b/codebasin/file_parser.py index 05b0f30..01727e6 100644 --- a/codebasin/file_parser.py +++ b/codebasin/file_parser.py @@ -8,7 +8,7 @@ import logging import os -from codebasin import preprocessor, util +from codebasin import preprocessor from codebasin.file_source import get_file_source log = logging.getLogger(__name__) @@ -170,11 +170,7 @@ def parse_file(self, *, summarize_only=True, language=None): f"{filename} doesn't appear " + "to be a language this tool can process", ) - with util.safe_open_read_nofollow( - filename, - mode="r", - errors="replace", - ) as source_file: + with open(filename, errors="replace") as source_file: groups = { "code": LineGroup(), "directive": LineGroup(), diff --git a/codebasin/preprocessor.py b/codebasin/preprocessor.py index 0a37ca2..03c189c 100644 --- a/codebasin/preprocessor.py +++ b/codebasin/preprocessor.py @@ -616,7 +616,7 @@ def __init__(self, _filename): def __compute_file_hash(self): chunk_size = 4096 hasher = hashlib.sha512() - with util.safe_open_read_nofollow(self.filename, "rb") as in_file: + with open(self.filename, "rb") as in_file: for chunk in iter(lambda: in_file.read(chunk_size), b""): hasher.update(chunk) diff --git a/codebasin/util.py b/codebasin/util.py index 0aebb6a..6082324 100644 --- a/codebasin/util.py +++ b/codebasin/util.py @@ -75,12 +75,6 @@ def safe_open_write_binary(fname): return os.fdopen(fpid, "wb") -def safe_open_read_nofollow(fname, *args, **kwargs): - """Open fname for reading, but don't follow links.""" - fpid = os.open(fname, os.O_RDONLY | os.O_NOFOLLOW) - return os.fdopen(fpid, *args, **kwargs) - - def valid_path(path): """Return true if the path passed in is valid""" valid = True