@@ -373,6 +373,44 @@ def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or
373373 write_lock ( target_lockfile , preserve_unknown_sections )
374374 end
375375
376+ def write_lock ( file , preserve_unknown_sections )
377+ return if Definition . no_lock || file . nil?
378+
379+ contents = to_lock
380+
381+ # Convert to \r\n if the existing lock has them
382+ # i.e., Windows with `git config core.autocrlf=true`
383+ contents . gsub! ( /\n / , "\r \n " ) if @lockfile_contents . match? ( "\r \n " )
384+
385+ if @locked_bundler_version
386+ locked_major = @locked_bundler_version . segments . first
387+ current_major = bundler_version_to_lock . segments . first
388+
389+ updating_major = locked_major < current_major
390+ end
391+
392+ preserve_unknown_sections ||= !updating_major && ( Bundler . frozen_bundle? || !( unlocking? || @unlocking_bundler ) )
393+
394+ if File . exist? ( file ) && lockfiles_equal? ( @lockfile_contents , contents , preserve_unknown_sections )
395+ return if Bundler . frozen_bundle?
396+ SharedHelpers . filesystem_access ( file ) { FileUtils . touch ( file ) }
397+ return
398+ end
399+
400+ if Bundler . frozen_bundle?
401+ Bundler . ui . error "Cannot write a changed lockfile while frozen."
402+ return
403+ end
404+
405+ begin
406+ SharedHelpers . filesystem_access ( file ) do |p |
407+ File . open ( p , "wb" ) { |f | f . puts ( contents ) }
408+ end
409+ rescue ReadOnlyFileSystemError
410+ raise ProductionError , lockfile_changes_summary ( "file system is read-only" )
411+ end
412+ end
413+
376414 def locked_ruby_version
377415 return unless ruby_version
378416 if @unlocking_ruby || !@locked_ruby_version
@@ -574,44 +612,6 @@ def lockfile_exists?
574612 lockfile && File . exist? ( lockfile )
575613 end
576614
577- def write_lock ( file , preserve_unknown_sections )
578- return if Definition . no_lock || file . nil?
579-
580- contents = to_lock
581-
582- # Convert to \r\n if the existing lock has them
583- # i.e., Windows with `git config core.autocrlf=true`
584- contents . gsub! ( /\n / , "\r \n " ) if @lockfile_contents . match? ( "\r \n " )
585-
586- if @locked_bundler_version
587- locked_major = @locked_bundler_version . segments . first
588- current_major = bundler_version_to_lock . segments . first
589-
590- updating_major = locked_major < current_major
591- end
592-
593- preserve_unknown_sections ||= !updating_major && ( Bundler . frozen_bundle? || !( unlocking? || @unlocking_bundler ) )
594-
595- if File . exist? ( file ) && lockfiles_equal? ( @lockfile_contents , contents , preserve_unknown_sections )
596- return if Bundler . frozen_bundle?
597- SharedHelpers . filesystem_access ( file ) { FileUtils . touch ( file ) }
598- return
599- end
600-
601- if Bundler . frozen_bundle?
602- Bundler . ui . error "Cannot write a changed lockfile while frozen."
603- return
604- end
605-
606- begin
607- SharedHelpers . filesystem_access ( file ) do |p |
608- File . open ( p , "wb" ) { |f | f . puts ( contents ) }
609- end
610- rescue ReadOnlyFileSystemError
611- raise ProductionError , lockfile_changes_summary ( "file system is read-only" )
612- end
613- end
614-
615615 def resolver
616616 @resolver ||= new_resolver ( resolution_base )
617617 end
0 commit comments