Skip to content

Commit

Permalink
Set asset-cached file ctime and mtime to the max mtime of the combine…
Browse files Browse the repository at this point in the history
…d files. Allows for consistent ETag generation without having a shared filesystem.
  • Loading branch information
jeremy committed Aug 13, 2008
1 parent 45b79d9 commit 1b127fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions actionpack/lib/action_view/helpers/asset_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion actionpack/test/template/asset_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" />),
Expand Down

2 comments on commit 1b127fc

@methodmissing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@yaroslav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second that, asset caching is broken.

Please sign in to comment.