Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bundle lock always touch the lockfile in non-frozen mode #7220

Merged
merged 3 commits into from Dec 12, 2023

Conversation

franzliedke
Copy link
Contributor

@franzliedke franzliedke commented Dec 2, 2023

Fixes #7120.

What was the end-user or developer problem that led to this PR?

In #7120, @hadmut mentioned problems with Make-based build pipelines: Gemfile.lock would not be "touched" (receive an updated file modification date) when running bundle lock is a no-op (i.e. the lockfile already matches the Gemfile).

What is your fix for the problem, implemented in this PR?

An explicit FileUtils.touch call. 馃

Make sure the following tasks are checked

@@ -339,7 +339,10 @@ def lock(file, preserve_unknown_sections = false)

preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))

return if file && File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
if file && File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
FileUtils.touch(file)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I wrap this in a SharedHelpers.filesystem_access block as well? 馃

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that helper unifies error rescuing for filesystem access problems. Touch is a write to the filesystem.

Copy link
Member

Choose a reason for hiding this comment

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

Tell me what you think. Should we copy the frozen bundle check to guard the touch? I know for lock it temporarily unfreezes because it's nonsensical otherwise, but this code path will run during install and update, I believe. We should not otherwise change the lockfile if frozen, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're referring to the little "Cannot write a changed lockfile while frozen" guard directly below, right? Yes, I also caught that and it seemed sensible not to touch the lockfile when frozen, but I did not add an explicit test about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I applied the wrapper. Anything else?

@martinemde
Copy link
Member

This is great! Thanks for working on this and thanks for including the test coverage.

I added some questions inline and then this should be fairly simple to get merged.

Comment on lines +343 to +347
SharedHelpers.filesystem_access(file) {|p| FileUtils.touch(p) }
return
Copy link
Member

Choose a reason for hiding this comment

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

I would specifically return without touching the lockfile if the bundle is frozen, like so:

Suggested change
SharedHelpers.filesystem_access(file) {|p| FileUtils.touch(p) }
return
return if Bundler.frozen_bundle?
SharedHelpers.filesystem_access(file) {|p| FileUtils.touch(p) }
return

Copy link
Member

Choose a reason for hiding this comment

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

I'd likewise add a test that it is not touched when frozen. Maybe here, since the lock command always temporarily unfreezes.

@martinemde martinemde self-assigned this Dec 11, 2023
@martinemde martinemde merged commit b08f2f1 into rubygems:master Dec 12, 2023
80 checks passed
@martinemde
Copy link
Member

Hey @franzliedke, I decided to go ahead and merge this now since I want to see it make it into the 2.5.0 bundler release. I'll update with the test I was imagining. Thanks for your contribution!

@franzliedke franzliedke deleted the fl/7120-bundle-lock-touch branch December 13, 2023 19:28
@franzliedke
Copy link
Contributor Author

@martinemde Thanks! To be honest, I was hoping this would happen. 馃槄 I wasn't 100% sure about the implications in these other commands that I wasn't aware of.

@deivid-rodriguez deivid-rodriguez changed the title bundle lock: Always touch the lockfile Make bundle lock always touch the lockfile in non-frozen mode Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

give bundler lock an option to force touching Gemfile.lock
3 participants