From 95a280fc616c8a337c6a80773e1022dbda4e9b38 Mon Sep 17 00:00:00 2001 From: John Pennycook Date: Thu, 10 Oct 2024 13:58:32 +0100 Subject: [PATCH] Optimize path handling realpath() resolves any and all symlinks in the path; in situations where we just need to store or print an absolute path, we should use abspath() instead. Signed-off-by: John Pennycook --- codebasin/__main__.py | 4 ++-- codebasin/config.py | 8 ++++---- codebasin/file_parser.py | 2 +- codebasin/platform.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/codebasin/__main__.py b/codebasin/__main__.py index 32c2f78..62ed1f4 100755 --- a/codebasin/__main__.py +++ b/codebasin/__main__.py @@ -271,14 +271,14 @@ def main(): args.reports = ["all"] # Determine the root directory based on where codebasin is run. - rootdir = os.path.realpath(os.getcwd()) + rootdir = os.path.abspath(os.getcwd()) # Set up a default configuration object. configuration = {} # Load the analysis file if it exists. if args.analysis_file is not None: - path = os.path.realpath(args.analysis_file) + path = os.path.abspath(args.analysis_file) if os.path.exists(path): if not os.path.splitext(path)[1] == ".toml": raise RuntimeError(f"Analysis file {path} must end in .toml.") diff --git a/codebasin/config.py b/codebasin/config.py index 047abcd..04b0883 100644 --- a/codebasin/config.py +++ b/codebasin/config.py @@ -324,7 +324,7 @@ def load_database(dbpath, rootdir): # Include paths may be specified relative to root include_paths = [ - os.path.realpath(os.path.join(rootdir, f)) for f in include_paths + os.path.abspath(os.path.join(rootdir, f)) for f in include_paths ] # Files may be specified: @@ -336,15 +336,15 @@ def load_database(dbpath, rootdir): if os.path.isabs(command.directory): filedir = command.directory else: - filedir = os.path.realpath( + filedir = os.path.abspath( rootdir, os.path.join(command.directory), ) if os.path.isabs(command.filename): - path = os.path.realpath(command.filename) + path = os.path.abspath(command.filename) else: - path = os.path.realpath(os.path.join(filedir, command.filename)) + path = os.path.abspath(os.path.join(filedir, command.filename)) # Compilation database may contain files that don't # exist without running make diff --git a/codebasin/file_parser.py b/codebasin/file_parser.py index a57f248..05b0f30 100644 --- a/codebasin/file_parser.py +++ b/codebasin/file_parser.py @@ -91,7 +91,7 @@ class FileParser: """ def __init__(self, _filename): - self._filename = os.path.realpath(_filename) + self._filename = os.path.abspath(_filename) @staticmethod def handle_directive(out_tree, groups, logical_line): diff --git a/codebasin/platform.py b/codebasin/platform.py index eba6ecd..c3b3bce 100644 --- a/codebasin/platform.py +++ b/codebasin/platform.py @@ -97,7 +97,7 @@ def find_include_file(self, filename, this_path, is_system_include=False): # Determine the path to the include file, if it exists for path in local_paths + self._include_paths: - test_path = os.path.realpath(os.path.join(path, filename)) + test_path = os.path.abspath(os.path.join(path, filename)) if os.path.isfile(test_path): include_file = test_path self.found_incl[filename] = include_file