heroku / buildpacks-ruby

Heroku's Cloud Native Buildpack for Ruby applications.
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Close #302 Preserve mtime when copying to/from the cache #336

Closed schneems closed 3 days ago

schneems commented 3 days ago

Commits have more details. The short version is that I confirmed in https://github.com/heroku/buildpacks-ruby/issues/302#issuecomment-2415128173 that mtime behavior is preserved with the CNB cache. However, the fs_extra method of copying to/from the cache did not preserve mtime. The cp_r library is built to handle this case.

schneems commented 3 days ago

Error on second run with the cache:

- Debug info
  - Could not move files out of the application to the cache.
    From: /workspace/tmp/cache/assets To: /layers/heroku_ruby/cache_tmp_cache_assets
    Error: creating directory: /layers/heroku_ruby/cache_tmp_cache_assets/sprockets: File exists (os error 17)

! Error caching frontend assets
!
! An error occurred while attempting to cache frontend assets, and the Ruby buildpack
! cannot continue.
!
! Ensure that the permissions on the files in your application directory are correct and that
! all symlinks correctly resolve.

ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51

Is due to cp_r. I misread the docs it says:

Overwrite existing directories or files.

However, it's under the banner "Missing features that could be added". It seems easy enough to implement following fs_err's API https://docs.rs/fs_extra/1.3.0/fs_extra/dir/struct.CopyOptions.html.

Alternatively we could have an on_conflict API that took a Fn(&Path, &Path) -> Result<&Path, Error> where it passes in the path to both the from and to paths and lets you return the path to the one you want to keep (or optionally raise an error. It's a little more verbose, but would allow for all possible combinations with a single API.

schneems commented 3 days ago

Closing in favor of #337