summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/file_system
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2021-12-17 08:57:33 -0800
committerTim Smith <tsmith84@gmail.com>2021-12-17 08:57:33 -0800
commit06c650886daa2a6eaf4c029cbf686ff401d44c48 (patch)
tree414a5bc2f8c7a5f07702a01c3fcb71b67026f189 /lib/chef/chef_fs/file_system
parentdf9b3881518297274bebfac3c348d69f3de52197 (diff)
downloadchef-06c650886daa2a6eaf4c029cbf686ff401d44c48.tar.gz
Simplify file readssimplified_read
This is a new RuboCop cop that moves things to file.read an file.binread vs. an open and then a read. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/chef_fs/file_system')
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/base_file.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/file_system_entry.rb2
3 files changed, 3 insertions, 3 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
index c49ed51d81..35e412bd37 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb
@@ -38,7 +38,7 @@ class Chef
def read
tmpfile = rest.streaming_request(file[:url])
- File.open(tmpfile, "rb", &:read)
+ File.binread(tmpfile)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:read, self, e, "Timeout reading #{file[:url]}: #{e}")
rescue Net::HTTPClientException => e
diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb
index 94b52b9201..46c6494bb7 100644
--- a/lib/chef/chef_fs/file_system/repository/base_file.rb
+++ b/lib/chef/chef_fs/file_system/repository/base_file.rb
@@ -123,7 +123,7 @@ class Chef
if is_ruby_file?
data_handler.from_ruby(file_path).to_json
else
- File.open(file_path, "rb", &:read)
+ File.binread(file_path)
end
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
index 902bc63038..289ec26058 100644
--- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
+++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
@@ -126,7 +126,7 @@ class Chef
end
def read
- File.open(file_path, "rb", &:read)
+ File.binread(file_path)
rescue Errno::ENOENT
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end