mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Move ScannedFile class and associated globals into ScannedFile.h and out of Net.h and scan.l
This commit is contained in:
parent
01ce18894b
commit
d608e7c9a5
7 changed files with 120 additions and 91 deletions
56
src/ScannedFile.cc
Normal file
56
src/ScannedFile.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "ScannedFile.h"
|
||||
|
||||
#include <sys/errno.h>
|
||||
#include <limits.h> // for PATH_MAX
|
||||
|
||||
#include "DebugLogger.h"
|
||||
#include "Reporter.h"
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::list<ScannedFile> files_scanned;
|
||||
std::vector<std::string> sig_files;
|
||||
|
||||
ScannedFile::ScannedFile(int arg_include_level,
|
||||
std::string arg_name,
|
||||
bool arg_skipped,
|
||||
bool arg_prefixes_checked)
|
||||
: 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
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
auto res = realpath(name.data(), buf);
|
||||
|
||||
if ( ! res )
|
||||
zeek::reporter->FatalError("failed to get realpath() of %s: %s",
|
||||
name.data(), strerror(errno));
|
||||
|
||||
canonical_path = res;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScannedFile::AlreadyScanned() const
|
||||
{
|
||||
auto rval = false;
|
||||
|
||||
for ( const auto& it : files_scanned )
|
||||
if ( it.canonical_path == canonical_path )
|
||||
{
|
||||
rval = true;
|
||||
break;
|
||||
}
|
||||
|
||||
DBG_LOG(zeek::DBG_SCRIPTS, "AlreadyScanned result (%d) %s", rval, canonical_path.data());
|
||||
return rval;
|
||||
}
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
||||
std::list<zeek::detail::ScannedFile>& files_scanned = zeek::detail::files_scanned;
|
||||
std::vector<std::string>& sig_files = zeek::detail::sig_files;
|
Loading…
Add table
Add a link
Reference in a new issue