summaryrefslogtreecommitdiff
path: root/lib/rubygems/config_file.rb
diff options
context:
space:
mode:
authorJosef Šimánek <josef.simanek@gmail.com>2022-10-29 02:47:14 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-11-11 17:24:08 +0900
commit7ce0f81fbbd9c2b35e9fe35f5ef040626e284a88 (patch)
tree7bad4d0b3734a3c075b489cf6bcb53adbefcebbf /lib/rubygems/config_file.rb
parentc7d043065c058f20ce30c61bb3ce127cb15cc0a8 (diff)
[rubygems/rubygems] Use file in XDG_STATE_HOME directory to store last update check timestamp.
https://github.com/rubygems/rubygems/commit/0fbc4ace8a
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6715
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r--lib/rubygems/config_file.rb33
1 files changed, 27 insertions, 6 deletions
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