You do not have access to this ticket

This project is archived and is in readonly mode.

#2738 ✓duplicate
Christos Zisopoulos

[PATCH] Fix zero length stylesheet cache files bug in case of missing CSS files

Reported by Christos Zisopoulos | May 29th, 2009 @ 04:45 PM | in 3.0.2

There appears to be a bug with the caching version of stylesheet_link_tag that results in a all.css cache file of zero bytes (when run in production) if a missing css filename is passed as a parameter

  stylesheet_link_tag('application', 'missing_css_file', :cache => true)

What happens is that the first time around after a deploy to production, a Errno::ENOENT is raised by the code trying to join the missing file with the rest of the CSS files. However, all.css has already been opened for writing and, after the exception is raised and not handled, a zero length all.css file is left behind.

Subsequent requests serve that zero length file instead, and so we get an unexpected CSS naked day

Attached is a test case and a patch.

I've opted for ignoring the missing asset files and creating the cached assets file anyway, but it might be better to just remove the cache file altogether and raise an exception like this

  begin
    File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
  rescue Exception => e
    File.unlink(joined_asset_path)
    raise e
  end

What do people think? I can upload that patch instead, if it is better.

Patch against master.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>