Strange behavior when building .crt files

One of my Middleman sites has a “files” directory which contains a few text files that should be available as-is in the built version (text files, etc). This has been working fine, but today I tried to add a copy of my public S/MIME certificate to this directory and I’m seeing some really strange build behavior.

The files directory is at source/files and the output should be public/files (my :build_dir = "public"). I also have a directory at source/media that contains images used for blog articles, stored in YYYY/MM dated folders.

When I build the site, most static files in the source/files directory are copied to public/files as they should be. But my certificate file is not. Rather, it’s copied into a strange subdirectory of source/media.

I know that doesn’t make sense, so I’ll illustrate:

$ find . -name kwilson.crt
./source/files/kwilson.crt

$ bundle exec middleman build
[...] (typical build output)

$ find . -name kwilson.crt
./source/media/2013/11/public/files/kwilson.crt
./source/files/kwilson.crt

$ find public -name kwilson.crt
$ 

What?

The directory at source/media/2013/11 already existed but there’s nothing but images in there. The “public” subdirectory was created during the build process. Note that the certificate file does not exist anywhere in the build output directory.

There’s nothing special about that source/media/2013/11 directory. It’s neither the first nor last directory in the media folder, and there’s nothing in it but 128 JPGs. It’s always this folder that the .crt ends up in though.

Deleting the source/media directory allows the build to work correctly, but that’s obviously not an option. This media directory is only mentioned once in config.rb:

activate :asset_hash, :ignore => /(files|media)\/.*/

I’ve confirmed this behavior with both .crt and .pem file extensions, but if I rename the file to .txt it works as expected. Likewise, if I create a regular text file with a .crt extension the same problem occurs (so it’s not the file itself).

I’m running middleman-core 3.3.10 with Ruby 1.9.3 on Ubuntu 12.04.

Any thoughts on where I can look next for the source of this problem?

No idea on what can cause your problem, but a workaround could be to ignore the crt and pem files during build, and then move them in after_build.

That workaround is what I ended up doing, but I’m still very curious as to what could cause this issue, as it really makes no sense at all. I’ll update this thread if I can figure it out. Thanks.

Bizarre. Is the destination path being generated incorrectly?

$ middleman console
middleman:~$ resource = sitemap.find_resource_by_path('files/kwilson.crt');
middleman:~$ resource.destination_path
=> "files/kwilson.crt"

Or perhaps something (image processing via an external program?) is changing the working directory and not changing back.

Thanks Andrew. I just tried this and the output is as expected, files/kwilson.crt.

This is an really simple site, just running Middleman and Middleman Blog, with no external processing happening during build.