mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
GH-237: add @load foo.bro
-> foo.zeek fallback
When failing to locate a script with explicit .bro suffix, check for whether one with a .zeek suffix exists and use it instead.
This commit is contained in:
parent
8f82ecc66d
commit
f21e11d811
6 changed files with 43 additions and 5 deletions
16
src/util.cc
16
src/util.cc
|
@ -1298,6 +1298,14 @@ string find_file(const string& filename, const string& path_set,
|
|||
return string();
|
||||
}
|
||||
|
||||
static bool ends_with(const std::string& s, const std::string& ending)
|
||||
{
|
||||
if ( ending.size() > s.size() )
|
||||
return false;
|
||||
|
||||
return std::equal(ending.rbegin(), ending.rend(), s.rbegin());
|
||||
}
|
||||
|
||||
string find_script_file(const string& filename, const string& path_set)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
@ -1313,6 +1321,14 @@ string find_script_file(const string& filename, const string& path_set)
|
|||
return f;
|
||||
}
|
||||
|
||||
if ( ends_with(filename, ".bro") )
|
||||
{
|
||||
// We were looking for a file explicitly ending in .bro and didn't
|
||||
// find it, so fall back to one ending in .zeek, if it exists.
|
||||
auto fallback = string(filename.data(), filename.size() - 4) + ".zeek";
|
||||
return find_script_file(fallback, path_set);
|
||||
}
|
||||
|
||||
return string();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue