Move running of git-restore-mtime to lib/fixup.rb and Simplify usage of @last_update_check (#12681)

* Move running of git-restore-mtime to lib/fixup.rb

* Simplify usage of @last_update_check
This commit is contained in:
Maximilian Downey Twiss
2025-09-03 23:22:54 +10:00
committed by GitHub
parent ea499756a2
commit 83587e5f3d
3 changed files with 12 additions and 14 deletions

View File

@@ -247,17 +247,10 @@ def update
to_update = `cd #{CREW_LIB_PATH} && git show --name-only HEAD..FETCH_HEAD`.include?('lib/const.rb')
system('git reset --hard FETCH_HEAD', chdir: CREW_LIB_PATH, exception: true)
system(<<~GIT_RESTORE_MTIME_COMMAND, chdir: CREW_LIB_PATH, exception: true) if File.file?("#{CREW_PREFIX}/bin/git-restore-mtime")
# Set the mtime on each file in git to the date the file was added,
# not to the date of the last git pull.
git-restore-mtime -sq 2>/dev/null
GIT_RESTORE_MTIME_COMMAND
puts 'Updating RubyGems.'.orange
system 'gem update -N --system'
system 'gem cleanup'
if Time.now.to_i - @last_update_check > (CREW_UPDATE_CHECK_INTERVAL * 3600 * 24)
puts 'Updating RubyGems.'.orange
system 'gem update -N --system'
system 'gem cleanup'
end
puts 'Package lists, crew, and library updated.'
# If lib/const.rb was changed, CREW_VERSION was bumped, so we re-run crew update.
@@ -2054,9 +2047,9 @@ end
@device = ConvenienceFunctions.load_symbolized_json
@last_update_check = Dir["#{CREW_LIB_PATH}/{.git/FETCH_HEAD,lib/const.rb}"].compact.map { |i| File.mtime(i).utc.to_i }.max
crewlog("The last update was #{MiscFunctions.time_difference(@last_update_check, Time.now.to_i)} ago.")
if ARGV[0] != 'update' && Time.now.to_i - @last_update_check > ((CREW_UPDATE_CHECK_INTERVAL * 3600 * 24))
last_update_check = Dir["#{CREW_LIB_PATH}/{.git/FETCH_HEAD,lib/const.rb}"].compact.map { |i| File.mtime(i).utc.to_i }.max
crewlog("The last update was #{MiscFunctions.time_difference(last_update_check, Time.now.to_i)} ago.")
if ARGV[0] != 'update' && Time.now.to_i - last_update_check > ((CREW_UPDATE_CHECK_INTERVAL * 3600 * 24))
plural = CREW_UPDATE_CHECK_INTERVAL < 2 ? '' : 's'
puts "It has been more than #{CREW_UPDATE_CHECK_INTERVAL} day#{plural} since crew was last updated. Please run 'crew update'.".lightpurple
end

View File

@@ -4,7 +4,7 @@ require 'etc'
require 'open3'
OLD_CREW_VERSION ||= defined?(CREW_VERSION) ? CREW_VERSION : '1.0'
CREW_VERSION ||= '1.65.8' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION
CREW_VERSION ||= '1.65.9' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION
# Kernel architecture.
KERN_ARCH ||= Etc.uname[:machine]

View File

@@ -32,6 +32,11 @@ ARCH ||= %w[aarch64 armv8l].include?(KERN_ARCH) ? 'armv7l' : KERN_ARCH
LIBC_VERSION ||= Etc.confstr(Etc::CS_GNU_LIBC_VERSION).split.last
CREW_PACKAGES_PATH ||= File.join(CREW_LIB_PATH, 'packages')
# Commands run immediately after updating from git.
# Set the mtime on each file to the timestamp of the most recent commit that modified the file.
system('git-restore-mtime -sq 2>/dev/null', chdir: CREW_LIB_PATH, exception: true) if File.file?("#{CREW_PREFIX}/bin/git-restore-mtime")
# Removing files/directories.
# Remove deprecated directory.