Skip to content

Commit

Permalink
util/rubocop -A --only Style/NumericLiteralPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Apr 11, 2023
1 parent 65e2760 commit d89cc31
Show file tree
Hide file tree
Showing 36 changed files with 198 additions and 198 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems.rb
Expand Up @@ -429,7 +429,7 @@ def self.ensure_default_gem_subdirectories(dir = Gem.dir, mode = nil)

def self.ensure_subdirectories(dir, mode, subdirs) # :nodoc:
old_umask = File.umask
File.umask old_umask | 002
File.umask old_umask | 0o002

options = {}

Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/commands/cert_command.rb
Expand Up @@ -178,7 +178,7 @@ def build_key # :nodoc:

algorithm = options[:key_algorithm] || Gem::Security::DEFAULT_KEY_ALGORITHM
key = Gem::Security.create_key(algorithm)
key_path = Gem::Security.write key, "gem-private_key.pem", 0600, passphrase
key_path = Gem::Security.write key, "gem-private_key.pem", 0o600, passphrase

[key, key_path]
end
Expand Down Expand Up @@ -291,7 +291,7 @@ def sign(cert_file)
cert = File.read cert_file
cert = OpenSSL::X509::Certificate.new cert

permissions = File.stat(cert_file).mode & 0777
permissions = File.stat(cert_file).mode & 0o777

issuer_cert = options[:issuer_cert]
issuer_key = options[:key]
Expand Down
14 changes: 7 additions & 7 deletions lib/rubygems/commands/setup_command.rb
Expand Up @@ -243,7 +243,7 @@ def execute
end

def install_executables(bin_dir)
prog_mode = options[:prog_mode] || 0755
prog_mode = options[:prog_mode] || 0o755

executables = { "gem" => "bin" }
executables.each do |tool, path|
Expand Down Expand Up @@ -369,7 +369,7 @@ def install_default_bundler_gem(bin_dir)
File.dirname(loaded_from)
else
target_specs_dir = File.join(default_dir, "specifications", "default")
mkdir_p target_specs_dir, :mode => 0755
mkdir_p target_specs_dir, :mode => 0o755
target_specs_dir
end

Expand All @@ -393,7 +393,7 @@ def install_default_bundler_gem(bin_dir)
end

bundler_bin_dir = bundler_spec.bin_dir
mkdir_p bundler_bin_dir, :mode => 0755
mkdir_p bundler_bin_dir, :mode => 0o755
bundler_spec.executables.each do |e|
cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
end
Expand Down Expand Up @@ -430,8 +430,8 @@ def make_destination_dirs
lib_dir, bin_dir = generate_default_dirs
end

mkdir_p lib_dir, :mode => 0755
mkdir_p bin_dir, :mode => 0755
mkdir_p lib_dir, :mode => 0o755
mkdir_p bin_dir, :mode => 0o755

[lib_dir, bin_dir]
end
Expand Down Expand Up @@ -639,10 +639,10 @@ def install_file(file, dest_dir)
dest_file = File.join dest_dir, file
dest_dir = File.dirname dest_file
unless File.directory? dest_dir
mkdir_p dest_dir, :mode => 0755
mkdir_p dest_dir, :mode => 0o755
end

install file, dest_file, :mode => options[:data_mode] || 0644
install file, dest_file, :mode => options[:data_mode] || 0o644
end

def remove_file_list(files, dir)
Expand Down
6 changes: 3 additions & 3 deletions lib/rubygems/config_file.rb
Expand Up @@ -241,9 +241,9 @@ def check_credentials_permissions
return if Gem.win_platform? # windows doesn't write 0600 as 0600
return unless File.exist? credentials_path

existing_permissions = File.stat(credentials_path).mode & 0777
existing_permissions = File.stat(credentials_path).mode & 0o777

return if existing_permissions == 0600
return if existing_permissions == 0o600

alert_error <<-ERROR
Your gem push credentials file located at:
Expand Down Expand Up @@ -326,7 +326,7 @@ def set_api_key(host, api_key)

Gem.load_yaml

permissions = 0600 & (~File.umask)
permissions = 0o600 & (~File.umask)
File.open(credentials_path, "w", permissions) do |f|
f.write config.to_yaml
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/indexer.rb
Expand Up @@ -327,7 +327,7 @@ def install_indices

def make_temp_directories
FileUtils.rm_rf @directory
FileUtils.mkdir_p @directory, :mode => 0700
FileUtils.mkdir_p @directory, :mode => 0o700
FileUtils.mkdir_p @quick_marshal_dir
end

Expand Down
14 changes: 7 additions & 7 deletions lib/rubygems/installer.rb
Expand Up @@ -316,7 +316,7 @@ def install
FileUtils.rm_rf spec.extension_dir

dir_mode = options[:dir_mode]
FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0755
FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0o755

if @options[:install_as_default]
extract_bin
Expand Down Expand Up @@ -495,7 +495,7 @@ def generate_bin # :nodoc:
next unless File.exist? bin_path

mode = File.stat(bin_path).mode
dir_mode = options[:prog_mode] || (mode | 0111)
dir_mode = options[:prog_mode] || (mode | 0o111)

unless dir_mode == mode
require "fileutils"
Expand Down Expand Up @@ -540,9 +540,9 @@ def generate_bin_script(filename, bindir)
require "fileutils"
FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers

File.open bin_script_path, "wb", 0755 do |file|
File.open bin_script_path, "wb", 0o755 do |file|
file.print app_script_text(filename)
file.chmod(options[:prog_mode] || 0755)
file.chmod(options[:prog_mode] || 0o755)
end

verbose bin_script_path
Expand Down Expand Up @@ -712,7 +712,7 @@ def check_that_user_bin_dir_is_in_path # :nodoc:
end

def verify_gem_home # :nodoc:
FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755
FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0o755
raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home)
end

Expand Down Expand Up @@ -934,7 +934,7 @@ def write_build_info_file
build_info_dir = File.join gem_home, "build_info"

dir_mode = options[:dir_mode]
FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755
FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0o755

build_info_file = File.join build_info_dir, "#{spec.full_name}.info"

Expand All @@ -957,7 +957,7 @@ def write_cache_file

def ensure_writable_dir(dir) # :nodoc:
begin
Dir.mkdir dir, *[options[:dir_mode] && 0755].compact
Dir.mkdir dir, *[options[:dir_mode] && 0o755].compact
rescue SystemCallError
raise unless File.directory? dir
end
Expand Down
12 changes: 6 additions & 6 deletions lib/rubygems/package.rb
Expand Up @@ -230,7 +230,7 @@ def add_checksums(tar)
end
end

tar.add_file_signed "checksums.yaml.gz", 0444, @signer do |io|
tar.add_file_signed "checksums.yaml.gz", 0o444, @signer do |io|
gzip_to io do |gz_io|
Psych.dump checksums_by_algorithm, gz_io
end
Expand All @@ -242,7 +242,7 @@ def add_checksums(tar)
# and adds this file to the +tar+.

def add_contents(tar) # :nodoc:
digests = tar.add_file_signed "data.tar.gz", 0444, @signer do |io|
digests = tar.add_file_signed "data.tar.gz", 0o444, @signer do |io|
gzip_to io do |gz_io|
Gem::Package::TarWriter.new gz_io do |data_tar|
add_files data_tar
Expand Down Expand Up @@ -278,7 +278,7 @@ def add_files(tar) # :nodoc:
# Adds the package's Gem::Specification to the +tar+ file

def add_metadata(tar) # :nodoc:
digests = tar.add_file_signed "metadata.gz", 0444, @signer do |io|
digests = tar.add_file_signed "metadata.gz", 0o444, @signer do |io|
gzip_to io do |gz_io|
gz_io.write @spec.to_yaml
end
Expand Down Expand Up @@ -382,7 +382,7 @@ def digest(entry) # :nodoc:
def extract_files(destination_dir, pattern = "*")
verify unless @spec

FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0755
FileUtils.mkdir_p destination_dir, :mode => dir_mode && 0o755

@gem.with_read_io do |io|
reader = Gem::Package::TarReader.new io
Expand Down Expand Up @@ -432,7 +432,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
FileUtils.rm_rf destination

mkdir_options = {}
mkdir_options[:mode] = dir_mode ? 0755 : (entry.header.mode if entry.directory?)
mkdir_options[:mode] = dir_mode ? 0o755 : (entry.header.mode if entry.directory?)
mkdir =
if entry.directory?
destination
Expand Down Expand Up @@ -468,7 +468,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
end

def file_mode(mode) # :nodoc:
((mode & 0111).zero? ? data_mode : prog_mode) ||
((mode & 0o111).zero? ? data_mode : prog_mode) ||
# If we're not using one of the default modes, then we're going to fall
# back to the mode from the tarball. In this case we need to mask it down
# to fit into 2^16 bits (the maximum value for a mode in CRuby since it
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/package/old.rb
Expand Up @@ -78,7 +78,7 @@ def extract_files(destination_dir)

FileUtils.rm_rf destination

FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0755
FileUtils.mkdir_p File.dirname(destination), :mode => dir_mode && 0o755

File.open destination, "wb", file_mode(entry["mode"]) do |out|
out.write file_data
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/package/tar_writer.rb
Expand Up @@ -192,7 +192,7 @@ def add_file_signed(name, mode, signer)
if signer.key
signature = signer.sign signature_digest.digest

add_file_simple "#{name}.sig", 0444, signature.length do |io|
add_file_simple "#{name}.sig", 0o444, signature.length do |io|
io.write signature
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/security.rb
Expand Up @@ -589,7 +589,7 @@ def self.trusted_certificates(&block)
# +permissions+. If passed +cipher+ and +passphrase+ those arguments will be
# passed to +to_pem+.

def self.write(pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER)
def self.write(pemmable, path, permissions = 0o600, passphrase = nil, cipher = KEY_CIPHER)
path = File.expand_path path

File.open path, "wb", permissions do |io|
Expand Down
8 changes: 4 additions & 4 deletions lib/rubygems/security/trust_dir.rb
Expand Up @@ -9,8 +9,8 @@ class Gem::Security::TrustDir
# Default permissions for the trust directory and its contents

DEFAULT_PERMISSIONS = {
:trust_dir => 0700,
:trusted_cert => 0600,
:trust_dir => 0o700,
:trusted_cert => 0o600,
}.freeze

##
Expand Down Expand Up @@ -91,7 +91,7 @@ def trust_cert(certificate)

destination = cert_path certificate

File.open destination, "wb", 0600 do |io|
File.open destination, "wb", 0o600 do |io|
io.write certificate.to_pem
io.chmod(@permissions[:trusted_cert])
end
Expand All @@ -109,7 +109,7 @@ def verify
"trust directory #{@dir} is not a directory" unless
File.directory? @dir

FileUtils.chmod 0700, @dir
FileUtils.chmod 0o700, @dir
else
FileUtils.mkdir_p @dir, :mode => @permissions[:trust_dir]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/specification_policy.rb
Expand Up @@ -234,7 +234,7 @@ def validate_permissions

@specification.files.each do |file|
next unless File.file?(file)
next if File.stat(file).mode & 0444 == 0444
next if File.stat(file).mode & 0o444 == 0o444
warning "#{file} is not world-readable"
end

Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/helper.rb
Expand Up @@ -477,7 +477,7 @@ def credential_setup
@temp_cred = File.join(@userhome, ".gem", "credentials")
FileUtils.mkdir_p File.dirname(@temp_cred)
File.write @temp_cred, ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
File.chmod 0600, @temp_cred
File.chmod 0o600, @temp_cred
end

def credential_teardown
Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/package/tar_test_case.rb
Expand Up @@ -163,11 +163,11 @@ def util_gem_data_tar(spec = nil, &block)
data_tgz = util_tar_gz(&block)
util_tar do |tar|
if spec
tar.add_file "metadata.gz", 0444 do |io|
tar.add_file "metadata.gz", 0o444 do |io|
io.write util_gzip(spec.to_yaml)
end
end
tar.add_file "data.tar.gz", 0644 do |io|
tar.add_file "data.tar.gz", 0o644 do |io|
io.write data_tgz.string
end
end
Expand Down

0 comments on commit d89cc31

Please sign in to comment.