From 2a8040039a22ad8deaec0f66a594d08f21d92814 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 28 Feb 2025 17:31:58 +0100 Subject: [PATCH] ScannedFile: Allow skipping canonicalization --- src/ScannedFile.cc | 8 ++++++-- src/ScannedFile.h | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ScannedFile.cc b/src/ScannedFile.cc index f6a5aa83cc..52df993ac5 100644 --- a/src/ScannedFile.cc +++ b/src/ScannedFile.cc @@ -13,14 +13,15 @@ namespace zeek::detail { std::list files_scanned; std::vector sig_files; -ScannedFile::ScannedFile(int arg_include_level, std::string arg_name, bool arg_skipped, bool arg_prefixes_checked) +ScannedFile::ScannedFile(int arg_include_level, std::string arg_name, bool arg_skipped, bool arg_prefixes_checked, + bool arg_is_canonical) : include_level(arg_include_level), skipped(arg_skipped), prefixes_checked(arg_prefixes_checked), name(std::move(arg_name)) { if ( name == canonical_stdin_path ) canonical_path = canonical_stdin_path; - else { + else if ( ! arg_is_canonical ) { std::error_code ec; auto canon = filesystem::canonical(name, ec); if ( ec ) @@ -28,6 +29,9 @@ ScannedFile::ScannedFile(int arg_include_level, std::string arg_name, bool arg_s canonical_path = canon.string(); } + else { + canonical_path = name; + } } bool ScannedFile::AlreadyScanned() const { diff --git a/src/ScannedFile.h b/src/ScannedFile.h index 05c816b912..2658d47f48 100644 --- a/src/ScannedFile.h +++ b/src/ScannedFile.h @@ -12,10 +12,13 @@ namespace zeek::detail { // Script file we have already scanned (or are in the process of scanning). // They are identified by normalized canonical path. +// +// If arg_is_canonical is set to true, assume arg_name is canonicalized and +// skip resolving the canonical name. class ScannedFile { public: ScannedFile(int arg_include_level, std::string arg_name, bool arg_skipped = false, - bool arg_prefixes_checked = false); + bool arg_prefixes_checked = false, bool arg_is_canonical = false); /** * Compares the canonical path of this file against every canonical path