Permalink
Browse files

Set asset-cached file ctime and mtime to the max mtime of the combine…

…d files. Allows for consistent ETag generation without having a shared filesystem.
  • Loading branch information...
1 parent 45b79d9 commit 1b127fcdea28d6c6ab2f2c6370125c8817ba99d6 @jeremy jeremy committed Aug 13, 2008
@@ -618,6 +618,11 @@ def join_asset_file_contents(paths)
def write_asset_file_contents(joined_asset_path, asset_paths)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
+
+ # Set mtime to the latest of the combined files to allow for
+ # consistent ETag without a shared filesystem.
+ mt = asset_paths.map { |p| File.mtime(File.join(ASSETS_DIR, p)) }.max
+ File.utime(mt, mt, joined_asset_path)
end
def collect_asset_files(*path)
@@ -425,7 +425,8 @@ def test_caching_stylesheet_link_tag_when_caching_on
stylesheet_link_tag(:all, :cache => true)
)
- assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
+ expected = Dir["#{ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR}/*.css"].map { |p| File.mtime(p) }.max
+ assert_equal expected, File.mtime(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
assert_dom_equal(
%(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),

2 comments on commit 1b127fc

Contributor

Raises with ‘No such file or directory’ – includes the timestamped suffix …

mt = asset_paths.map { |p| File.mtime(File.join(ASSETS_DIR, p).split(‘?’).first) }.max

Contributor

Second that, asset caching is broken.

Please sign in to comment.