Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def execute(cleanup_file)
# the CopyCommand entry should not even be created by Installer
cleanup_file.puts(@destination)
if File.symlink?(@source)
FileUtils.symlink(File.readlink(@source), @destination)
FileUtils.symlink(File.readlink(@source), @destination, :force => true)
else
FileUtils.copy(@source, @destination, :preserve => true)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/instance_agent/plugins/codedeploy/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def generate_normal_copy(i, absolute_source_path, destination)
when "DISALLOW"
raise "The deployment failed because a specified file already exists at this location: #{destination}"
when "OVERWRITE"
if File.directory?(destination)
raise "The deployment failed because a directory already exists at this location: #{destination}"
end
i.copy(absolute_source_path, destination)
when "RETAIN"
# neither generate copy command or fail the deployment
Expand Down
36 changes: 25 additions & 11 deletions test/instance_agent/plugins/codedeploy/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,31 @@ class CodeDeployPluginInstallerTest < InstanceAgentTestCase
end
end

should "generate a copy command if the file already exists and @file_exists_behavior is set to 'OVERWRITE'" do
@app_spec
.stubs(:files)
.returns([stub(:source => "src1",
:destination => "dst1")])
File.stubs(:exists?).with("dst1/src1").returns(true)
@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1", "dst1/src1")
@installer.file_exists_behavior = "OVERWRITE"
@installer.install(@deployment_group_id, @app_spec)
context "if the file already exists and @file_exists_behavior is set to 'OVERWRITE'" do
setup do
@app_spec
.stubs(:files)
.returns([stub(:source => "src1",
:destination => "dst1")])
File.stubs(:exists?).with("dst1/src1").returns(true)
@installer.file_exists_behavior = "OVERWRITE"
end

should "generate a copy command if destination is a regular file" do
File.stubs(:directory?).with("dst1/src1").returns(false)
@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1", "dst1/src1")
@installer.install(@deployment_group_id, @app_spec)
end

should "raise an error if destination is directory" do
File.stubs(:directory?).with("dst1/src1").returns(true)
File.stubs(:symlink?).with("dst1/src1").returns(false)
assert_raised_with_message("The deployment failed because a directory already exists at this location: dst1/src1") do
@installer.install(@deployment_group_id, @app_spec)
end
end
end

should "neither generate a copy command nor raise an error if the file already exists and @file_exists_behavior is set to 'RETAIN'" do
Expand Down