summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinay Satish <73982200+vinay-satish@users.noreply.github.com>2023-01-04 00:24:02 +0530
committerGitHub <noreply@github.com>2023-01-03 13:54:02 -0500
commite1d6df13eb8a3fdee8c6e416b8fcb2f9ef4380f8 (patch)
tree6d471a0e47f9954562c820e5ac6e068ba0e0bb5d
parent2504df67e85cd2602db571fccdeb23ee38c69b0e (diff)
downloadchef-e1d6df13eb8a3fdee8c6e416b8fcb2f9ef4380f8.tar.gz
updating file_system to send back the copy status (#13107)
* updating file_system to send back the copy status * Updating Gemfile.lock for cheffish bump Signed-off-by: Vinay Satish <vinay.satish@progress.com>
-rw-r--r--Gemfile.lock3
-rw-r--r--knife/Gemfile.lock2
-rw-r--r--knife/lib/chef/knife/download.rb3
-rw-r--r--knife/lib/chef/knife/upload.rb3
-rw-r--r--lib/chef/chef_fs/file_system.rb28
-rw-r--r--spec/unit/chef_fs/file_system_spec.rb2
6 files changed, 29 insertions, 12 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 8c2a15a5de..c72ee92b9f 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -33,7 +33,6 @@ GIT
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
-
GIT
remote: https://github.com/chef/ruby-shadow
revision: 3b8ea40b0e943b5de721d956741308ce805a5c3c
@@ -201,7 +200,7 @@ GEM
rack (~> 2.0, >= 2.0.6)
uuidtools (~> 2.1)
webrick
- cheffish (17.0.0)
+ cheffish (17.1.5)
chef-utils (>= 17.0)
chef-zero (>= 14.0)
net-ssh
diff --git a/knife/Gemfile.lock b/knife/Gemfile.lock
index b5d988d35b..4a71a1cff6 100644
--- a/knife/Gemfile.lock
+++ b/knife/Gemfile.lock
@@ -15,7 +15,7 @@ DEPENDENCIES
chef-config!
chef-utils!
chef-vault
- cheffish (>= 17)
+ cheffish (>= 17.1.5)
chefstyle
ed25519 (~> 1.2)
fauxhai-ng
diff --git a/knife/lib/chef/knife/download.rb b/knife/lib/chef/knife/download.rb
index 2eda642979..b7ceb31261 100644
--- a/knife/lib/chef/knife/download.rb
+++ b/knife/lib/chef/knife/download.rb
@@ -71,7 +71,8 @@ class Chef
error = false
pattern_args.each do |pattern|
- if Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs, local_fs, config[:recurse] ? nil : 1, config, ui, proc { |entry| format_path(entry) })
+ fs_error, result = Chef::ChefFS::FileSystem.copy_to(pattern, chef_fs, local_fs, config[:recurse] ? nil : 1, config, ui, proc { |entry| format_path(entry) })
+ if fs_error
error = true
end
end
diff --git a/knife/lib/chef/knife/upload.rb b/knife/lib/chef/knife/upload.rb
index e8dd052e77..17118247cb 100644
--- a/knife/lib/chef/knife/upload.rb
+++ b/knife/lib/chef/knife/upload.rb
@@ -73,7 +73,8 @@ class Chef
error = false
pattern_args.each do |pattern|
- if Chef::ChefFS::FileSystem.copy_to(pattern, local_fs, chef_fs, config[:recurse] ? nil : 1, config, ui, proc { |entry| format_path(entry) })
+ fs_error, result = Chef::ChefFS::FileSystem.copy_to(pattern, local_fs, chef_fs, config[:recurse] ? nil : 1, config, ui, proc { |entry| format_path(entry) })
+ if fs_error
error = true
end
end
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb
index 5c4278c100..5c086bc11c 100644
--- a/lib/chef/chef_fs/file_system.rb
+++ b/lib/chef/chef_fs/file_system.rb
@@ -140,17 +140,18 @@ class Chef
def self.copy_to(pattern, src_root, dest_root, recurse_depth, options, ui = nil, format_path = nil)
found_result = false
error = false
+ result = {}
list_pairs(pattern, src_root, dest_root).parallel_each do |src, dest|
found_result = true
new_dest_parent = get_or_create_parent(dest, options, ui, format_path)
- child_error = copy_entries(src, dest, new_dest_parent, recurse_depth, options, ui, format_path)
+ child_error, result = copy_entries(src, dest, new_dest_parent, recurse_depth, options, ui, format_path)
error ||= child_error
end
if !found_result && pattern.exact_path
ui.error "#{pattern}: No such file or directory on remote or local" if ui
error = true
end
- error
+ [error, result]
end
# Yield entries for children that are in either +a_root+ or +b_root+, with
@@ -275,6 +276,7 @@ class Chef
# case we shouldn't waste time trying PUT if we know the file doesn't
# exist.
# Will need to decide how that works with checksums, though.
+ result = { "total" => 0, "success_count" => 0, "failed" => [] }
error = false
begin
dest_path = format_path.call(dest_entry) if ui
@@ -290,6 +292,8 @@ class Chef
dest_entry.delete(true)
ui.output "Deleted extra entry #{dest_path} (purge is on)" if ui
rescue Chef::ChefFS::FileSystem::NotFoundError
+ failure = { "src_path" => src_path, "reason" => "Entry #{dest_path} does not exist" }
+ result["failed"].append(failure)
ui.output "Entry #{dest_path} does not exist. Nothing to do. (purge is on)" if ui
end
end
@@ -323,7 +327,7 @@ class Chef
if recurse_depth != 0
src_entry.children.parallel_each do |src_child|
new_dest_child = new_dest_dir.child(src_child.name)
- child_error = copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui, format_path)
+ child_error, result = copy_entries(src_child, new_dest_child, new_dest_dir, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui, format_path)
error ||= child_error
end
end
@@ -339,14 +343,15 @@ class Chef
else
# Both exist.
-
# If the entry can do a copy directly, do that.
if dest_entry.respond_to?(:copy_from)
if options[:force] || compare(src_entry, dest_entry)[0] == false
if options[:dry_run]
ui.output "Would update #{dest_path}" if ui
else
+ result["total"] += 1
dest_entry.copy_from(src_entry, options)
+ result["success_count"] += 1
ui.output "Updated #{dest_path}" if ui
end
end
@@ -359,7 +364,7 @@ class Chef
# If both are directories, recurse into their children
if recurse_depth != 0
child_pairs(src_entry, dest_entry).parallel_each do |src_child, dest_child|
- child_error = copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui, format_path)
+ child_error, result = copy_entries(src_child, dest_child, dest_entry, recurse_depth ? recurse_depth - 1 : recurse_depth, options, ui, format_path)
error ||= child_error
end
end
@@ -373,7 +378,6 @@ class Chef
ui.error("File #{src_path} is a regular file while file #{dest_path} is a directory\n") if ui
return
else
-
# Both are files! Copy them unless we're sure they are the same.'
if options[:diff] == false
should_copy = false
@@ -389,7 +393,9 @@ class Chef
ui.output "Would update #{dest_path}" if ui
else
src_value = src_entry.read if src_value.nil?
+ result["total"] += 1
dest_entry.write(src_value)
+ result["success_count"] += 1
ui.output "Updated #{dest_path}" if ui
end
end
@@ -397,17 +403,25 @@ class Chef
end
end
rescue RubyFileError => e
+ failure = { "src_path" => src_path, "reason" => e.reason }
+ result["failed"].append(failure)
ui.warn "#{format_path.call(e.entry)} #{e.reason}." if ui
rescue DefaultEnvironmentCannotBeModifiedError => e
+ failure = { "src_path" => src_path, "reason" => e.reason }
+ result["failed"].append(failure)
ui.warn "#{format_path.call(e.entry)} #{e.reason}." if ui
rescue OperationFailedError => e
+ failure = { "src_path" => src_path, "reason" => e.reason }
+ result["failed"].append(failure)
ui.error "#{format_path.call(e.entry)} failed to #{e.operation}: #{e.message}" if ui
error = true
rescue OperationNotAllowedError => e
+ failure = { "src_path" => src_path, "reason" => e.reason }
+ result["failed"].append(failure)
ui.error "#{format_path.call(e.entry)} #{e.reason}." if ui
error = true
end
- error
+ [error, result]
end
def get_or_create_parent(entry, options, ui, format_path)
diff --git a/spec/unit/chef_fs/file_system_spec.rb b/spec/unit/chef_fs/file_system_spec.rb
index 0d4ae6aa05..91d24c6dea 100644
--- a/spec/unit/chef_fs/file_system_spec.rb
+++ b/spec/unit/chef_fs/file_system_spec.rb
@@ -145,4 +145,6 @@ describe Chef::ChefFS::FileSystem, ruby: ">= 3.0" do
end
end
end
+
+ # Need to add the test case for copy_to method - not able to do the implimentation with Dir.mktmpdir
end