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
5 changes: 3 additions & 2 deletions lib/instance_agent/plugins/codedeploy/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generate_instructions(application_specification)
fi.source)

log(:debug, "generating instructions for copying #{fi.source} to #{fi.destination}")
if File.directory?(absolute_source_path)
if File.directory?(absolute_source_path) && !File.symlink?(absolute_source_path)
fill_in_missing_ancestors(i, fi.destination)
generate_directory_copy(i, absolute_source_path, fi.destination)
else
Expand Down Expand Up @@ -108,7 +108,8 @@ def generate_directory_copy(i, absolute_source_path, destination)
absolute_source_path = absolute_source_path.force_encoding("UTF-8");
absolute_entry_path = File.join(absolute_source_path, entry)
entry_destination = File.join(destination, entry)
if File.directory?(absolute_entry_path)

if File.directory?(absolute_entry_path) && !File.symlink?(absolute_entry_path)
generate_directory_copy(i, absolute_entry_path, entry_destination)
else
generate_normal_copy(i, absolute_entry_path, entry_destination)
Expand Down
87 changes: 87 additions & 0 deletions test/instance_agent/plugins/codedeploy/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,93 @@ class CodeDeployPluginInstallerTest < InstanceAgentTestCase

end # "regular files"

context "symbolic links" do

setup do
@app_spec
.stubs(:files)
.returns([stub(:source => "src1",
:destination => "dst1")])

File.stubs(:directory?).returns(false)
File.stubs(:directory?).with("dst1").returns(true)

File.stubs(:exists?).returns(false)
File.stubs(:exists?).with("dst1").returns(true)

@command_sequence = sequence("commands")
end

should "generate a copy command for the source file if it is a symbolic link of a regular file" do
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(false)
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(true)

@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1", "dst1/src1")
.in_sequence(@command_sequence)

@installer.install(@deployment_group_id, @app_spec)
end

should "generate a copy command instead of a mkdir command for the source file if it is a symbolic link of a directory" do
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(true)

@instruction_builder
.expects(:mkdir)
.with("dst1/src1")
.never
@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1", "dst1/src1")
.in_sequence(@command_sequence)

@installer.install(@deployment_group_id, @app_spec)
end

should "generate a copy command if the file inside the source directory is a symbolic link of a regular file" do
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
Dir.stubs(:entries)
.with("deploy-archive-dir/src1")
.returns([".", "..", "foo"])

File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(false)
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)

@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1/foo", "dst1/foo")
.in_sequence(@command_sequence)

@installer.install(@deployment_group_id, @app_spec)
end

should "generate a copy command instead of a mkdir command if the file inside the source directory is a symbolic link of a directory" do
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
Dir.stubs(:entries)
.with("deploy-archive-dir/src1")
.returns([".", "..", "foo"])

File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(true)
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)

@instruction_builder
.expects(:mkdir)
.with("dst1/foo")
.never
@instruction_builder
.expects(:copy)
.with("deploy-archive-dir/src1/foo", "dst1/foo")
.in_sequence(@command_sequence)

@installer.install(@deployment_group_id, @app_spec)
end

end # "symlinks"

context "directories" do

setup do
Expand Down