# Loading directories

**URL:** <https://community.zeek.org/t/loading-directories/1892>\
**Category:** Development\
**Tags:** development\
**Created:** [June 1, 2011, 7:08pm UTC](https://community.zeek.org/t/loading-directories/1892 "2011-06-01T19:08:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 1, 2011, 7:08pm UTC](https://community.zeek.org/t/loading-directories/1892/1 "2011-06-01T19:08:22Z")

</div>

For policy files, we now have sub-directory structures like this:

&nbsp;&nbsp;&nbsp;&nbsp;foo/base.bro  
&nbsp;&nbsp;&nbsp;&nbsp;foo/ext1.bro  
&nbsp;&nbsp;&nbsp;&nbsp;foo/ext2.bro  
&nbsp;&nbsp;&nbsp;&nbsp;foo.bro

foo.bro contains

&nbsp;&nbsp;&nbsp;&nbsp;@load foo/base.bro  
&nbsp;&nbsp;&nbsp;&nbsp;@load foo/ext1.bro  
&nbsp;&nbsp;&nbsp;&nbsp;@load foo/ext2.bro

And the effect is that "@load foo" pulls in all of the scripts at  
once, which is neat.

What I'm wondering hiwer is whether we should move "foo.bro" into the  
subdirectory under some magic name (like init.bro or \_\_init\_\_.bro or  
\_\_package\_\_.bro or ...). And then allow to write "@load foo" (with  
"foo" now being the directory name) with the effect of loading  
"foo/init.bro". In addition, inside foo/\* we could allow "@load  
ext1.bro" instead of "@load foo/ext1.bro".

(Coincidentally, this would be quite like Python does it ... 🙂

Robin

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [June 1, 2011, 7:22pm UTC](https://community.zeek.org/t/loading-directories/1892/2 "2011-06-01T19:22:33Z")

</div>

> What I'm wondering hiwer is whether we should move "foo.bro" into the  
> subdirectory under some magic name (like init.bro or \_\_init\_\_.bro or  
> \_\_package\_\_.bro or ...)

That makes a lot of sense to me. I've been thinking the same thing for a while, those wrapper scripts really litter things up for not much benefit.

> In addition, inside foo/\* we could allow "@load  
> ext1.bro" instead of "@load foo/ext1.bro".

Hm, I'm not totally sure I like this. It could get confusing when two scripts have the same name. If you want to load the software framework and you are in http/init.bro how do you do it if there is a file named http/software.bro?

> (Coincidentally, this would be quite like Python does it ... 🙂

I can go for copying syntax and idioms to make the language feel a bit more familiar and comfortable. 🙂

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 1, 2011, 7:51pm UTC](https://community.zeek.org/t/loading-directories/1892/3 "2011-06-01T19:51:22Z")

</div>

Good question. 🙂 Hmm... Then how about just using "@load ./ext1.bro"  
inside the directory. That should already work and also avoid the need  
to repeat the directory name.

Robin

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [June 1, 2011, 7:54pm UTC](https://community.zeek.org/t/loading-directories/1892/4 "2011-06-01T19:54:50Z")

</div>

That sounds better to me.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Jonathan\_Siwek](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Jonathan\_Siwek](https://community.zeek.org/u/Jonathan_Siwek)\
**Post date:** [June 1, 2011, 8:43pm UTC](https://community.zeek.org/t/loading-directories/1892/5 "2011-06-01T20:43:37Z")

</div>

> What I'm wondering hiwer is whether we should move "foo.bro" into the  
> subdirectory under some magic name (like init.bro or \_\_init\_\_.bro or  
> \_\_package\_\_.bro or ...). And then allow to write "@load foo" (with  
> "foo" now being the directory name) with the effect of loading  
> "foo/init.bro".

I think that makes sense to me.

A minor detail would be choosing which gets preference: a file or a directory. E.g. say you had a "foo.bro" file and a "foo/" directory that live on the same path, what does "@load foo" actually load?

> In addition, inside foo/\* we could allow "@load ext1.bro" instead of "@load foo/ext1.bro".  
> (Coincidentally, this would be quite like Python does it ... 🙂

Initially only seemed to me like a minor convenience is gained from this, but I can't really argue against making things more analogous to an existing language.

- Jon

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [June 1, 2011, 9:26pm UTC](https://community.zeek.org/t/loading-directories/1892/6 "2011-06-01T21:26:52Z")

</div>

> What I'm wondering hiwer is whether we should move "foo.bro" into the  
> subdirectory under some magic name (like init.bro or \_\_init\_\_.bro or  
> \_\_package\_\_.bro or ...)

How about just foo/foo.bro? That would avoid problem of referring to the  
wrong instance of the script due to confusion regarding what directory one  
is working out of.

BTW, if foo.bro itself pulls in ext1.bro etc., then what if the user doesn't  
\*want\* the ext1.bro functionality? Or is the model that they have to use  
it, and it's just split out into another script for keeping each script  
bite-sized?

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![Jonathan\_Siwek](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Jonathan\_Siwek](https://community.zeek.org/u/Jonathan_Siwek)\
**Post date:** [June 1, 2011, 9:44pm UTC](https://community.zeek.org/t/loading-directories/1892/7 "2011-06-01T21:44:36Z")

</div>

> BTW, if foo.bro itself pulls in ext1.bro etc., then what if the user  
> doesn't \*want\* the ext1.bro functionality? Or is the model that they have to  
> use it, and it's just split out into another script for keeping each  
> script bite-sized?

I remember seeing that the @unload directive exists and looks like it's supposed to prevent future @load's of a given script. Don't know if it works, but that could be a way for a user to blacklist the loading of certain scripts in a package.

- Jon

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 1, 2011, 10:51pm UTC](https://community.zeek.org/t/loading-directories/1892/8 "2011-06-01T22:51:13Z")

</div>

> How about just foo/foo.bro?

Hmm ... I think I'd prefer some visual indicator that the script is  
special, i.e., it gets loaded when the directory is specified. Having  
a consistent name for that would point that out.

> BTW, if foo.bro itself pulls in ext1.bro etc., then what if the user doesn't  
> \*want\* the ext1.bro functionality?

The model is that by "@load foo" he gets the full set. If he doesn't  
want that, he can still pick his pieces individually ("@load  
foo/base.bro; @load foo/ext2.bro").

The @unload may do it too, but I don't like that statement. 🙂

Robin

---

<div class="post-metadata">

**Author:** ![Jonathan\_Siwek](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Jonathan\_Siwek](https://community.zeek.org/u/Jonathan_Siwek)\
**Post date:** [June 2, 2011, 2:45pm UTC](https://community.zeek.org/t/loading-directories/1892/9 "2011-06-02T14:45:46Z")

</div>

> \> BTW, if foo.bro itself pulls in ext1.bro etc., then what if the  
> \> user doesn't \*want\* the ext1.bro functionality?
> 
> The model is that by "@load foo" he gets the full set. If he doesn't  
> want that, he can still pick his pieces individually ("@load  
> foo/base.bro; @load foo/ext2.bro").
> 
> The @unload may do it too, but I don't like that statement. 🙂

If it's just the name of @unload (I'd agree the sound of it is misleading), it could be offered as a different command that does the same thing.

I just think it's nice that a user can choose which approach is best for them: either a whitelist that picks individual pieces of a "package" or a blacklist that blocks only certain scripts of a "package". The blacklist approach allows a user to automatically start loading new scripts that get added to a package in future releases, but the whitelist must be manually updated in that situation.

- Jon

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 2, 2011, 4:22pm UTC](https://community.zeek.org/t/loading-directories/1892/10 "2011-06-02T16:22:32Z")

</div>

> If it's just the name of @unload (I'd agree the sound of it is  
> misleading), it could be offered as a different command that does the  
> same thing.

The name is one piece, but it can also be confusing if one unloads a  
script that some other one depends on and then suddendly doesn't work  
as expected anymore (or not at all). And the order of @loads and  
@unloads matters, which isn't nice either.

> I just think it's nice that a user can choose which approach is best  
> for them: either a whitelist that picks individual pieces of a  
> "package" or a blacklist that blocks only certain scripts of a  
> "package".

That's right, I'm not saying nobody should use @unload, but I don't  
want it to be the only part of the story. Having both options is  
indeed helpful.

Robin

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 3, 2011, 5:04am UTC](https://community.zeek.org/t/loading-directories/1892/11 "2011-06-03T05:04:16Z")

</div>

I've just commited this to master. The magic file name is  
"\_\_load\_\_.bro".

However, it turns out that "@load ./abc.bro" doesn't work because the  
cwd doesn't get adjusted when loading a file. That isn't easy to add,  
so I'm leaving that as it is. Seems fine for now.

Robin

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/loading-directories/1892/12 "2022-05-06T15:39:36Z")

</div>

Closed on May 6, 2022, 3:39pm UTC


