diff options
Diffstat (limited to 'lib/rubygems/config_file.rb')
-rw-r--r-- | lib/rubygems/config_file.rb | 33 |
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 |