Fixes to relative @load'ing.

The currently loading script's path is prepended (vs. appended) to
BROPATH to search for the @load'd file to prevent being overshadowed by
scripts/directories/packages in the normal BROPATH with the same name.

This extra search path should also only be prepended to BROPATH in the
case when the @load'd file we're looking for is actually relative
(i.e. the name starts with "./" or "../").
This commit is contained in:
Jon Siwek 2011-07-23 20:46:35 -05:00
parent 64bc53e621
commit 454fd9578e

View file

@ -972,11 +972,11 @@ FILE* search_for_file(const char* filename, const char* ext,
char path[1024], full_filename_buf[1024]; char path[1024], full_filename_buf[1024];
// Append the currently loading script's path to BROPATH so that // Prepend the currently loading script's path to BROPATH so that
// @loads can be referenced relatively. // @loads can be referenced relatively.
if ( current_scanned_file_path != "" ) if ( current_scanned_file_path != "" && filename[0] == '.' )
safe_snprintf(path, sizeof(path), "%s:%s", bro_path(), safe_snprintf(path, sizeof(path), "%s:%s",
current_scanned_file_path.c_str()); current_scanned_file_path.c_str(), bro_path());
else else
safe_strncpy(path, bro_path(), sizeof(path)); safe_strncpy(path, bro_path(), sizeof(path));