From 7ce0f81fbbd9c2b35e9fe35f5ef040626e284a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Sat, 29 Oct 2022 02:47:14 +0200 Subject: [rubygems/rubygems] Use file in XDG_STATE_HOME directory to store last update check timestamp. https://github.com/rubygems/rubygems/commit/0fbc4ace8a --- lib/rubygems/config_file.rb | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'lib/rubygems/config_file.rb') diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index b18f4115cc..f2abc7f2af 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -371,16 +371,18 @@ if you believe they were disclosed to a third party. @backtrace || $DEBUG end - # Check config file is writable. Creates empty file if not present to ensure we can write to it. - def config_file_writable? - if File.exist?(config_file_name) - File.writable?(config_file_name) + # Check state file is writable. Creates empty file if not present to ensure we can write to it. + def state_file_writable? + if File.exist?(state_file_name) + File.writable?(state_file_name) else require "fileutils" - FileUtils.mkdir_p File.dirname(config_file_name) - File.open(config_file_name, "w") {} + FileUtils.mkdir_p File.dirname(state_file_name) + File.open(state_file_name, "w") {} true end + rescue Errno::EACCES + false end # The name of the configuration file. @@ -388,6 +390,25 @@ if you believe they were disclosed to a third party. @config_file_name || Gem.config_file end + # The name of the state file. + def state_file_name + @state_file_name || Gem.state_file + end + + # Reads time of last update check from state file + def last_update_check + if File.readable?(state_file_name) + File.read(state_file_name).to_i + else + 0 + end + end + + # Writes time of last update check to state file + def last_update_check=(timestamp) + File.write(state_file_name, timestamp.to_s) if state_file_writable? + end + # Delegates to @hash def each(&block) hash = @hash.dup -- cgit v1.2.1