sprockets icon indicating copy to clipboard operation
sprockets copied to clipboard

assets:precompile always modifies mtime in the generated manifest

Open blampe opened this issue 3 years ago • 7 comments

Expected behavior

Running assets:precompile twice should produce identical asset manifests when none of the underlying assets have been modified.

Actual behavior

https://github.com/rails/sprockets/blob/2c38d99930421c22896a65e1d384edf90830f4c3/lib/sprockets/manifest.rb#L174

mtime is always modified. This produces an identical manifest except for the mtime fields:

     "foo-62ad8f466dff387634e10db2eebe215c9550ef654bbb597718d428e9fb90cfc5.css": {
       "logical_path": "foo .css",
-      "mtime": "2021-05-24T13:44:44-07:00",
+      "mtime": "2021-05-24T13:54:00-07:00",
       "size": 527213,
       "digest": "b7e651694fa30e3fd68adb375d7a3d14121d4e1b8fdf6ff06c6bc2a342967503",
       "integrity": "sha256-t+ZRaU+jDj/Wits3XXo9FBIdThuP32/wbGvCo0KWdQM="
     },

System configuration

  • Sprockets version: 4.0.2
  • Ruby version: 2.6.7

Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS

Setting

config.assets.manifest = "#{Rails.root}/public/assets/manifest.json

then running

rake assets:precompile; git add public/assets/manifest.json; rake assets:precompile; git status

should be sufficient to reproduce the behavior.

blampe avatar May 24 '21 21:05 blampe

It would be very nice to have a fix for this at some point.

matthewhively avatar Nov 29 '21 19:11 matthewhively

Shouldn't it be the mtime of asset itself as it was earlier?

asset.mtime.iso8601

vs37559 avatar Jul 28 '22 18:07 vs37559

I doubt it will. I was reviewing the code, and it seems asset mtime was intentionally removed. https://github.com/rails/sprockets/pull/197

brenogazzola avatar Jul 28 '22 20:07 brenogazzola

So I guess the mtime is supposed to be cached somewhere else and not rely on the timestamp reported by the OS? Unfortunately the PR you linked does not actually modify sprockets/manifest.rb line 174

matthewhively avatar Jul 28 '22 20:07 matthewhively

The manifest file was changed because the mtime method in Asset which it relied on was marked as deprecated. That PR is pretty much the only thing I managed to find about why the method was marked as deprecated, since the commit that did the deprecation did not give any reasoning for it: https://github.com/rails/sprockets/commit/e586dba6050861a424b88ec2330cde034ef430d2

brenogazzola avatar Jul 28 '22 20:07 brenogazzola

Any idea what the mtime is used for? Can we set it to be "1970-01-01 00:00:01" (Linux timestamp 1) and things will keep working?

ryantm avatar Sep 20 '22 20:09 ryantm

Nope, they won't. When running assets:clean Sprockets uses the mtime to decide which 3 versions it will keep. If they are all the same, there's no guarantee that the current version will be kept.

brenogazzola avatar Sep 21 '22 13:09 brenogazzola