Skip to content

Commit 0f4e34b

Browse files
committed
Generate a normal copy when installing a symlink of a directory
1 parent dc22129 commit 0f4e34b

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

lib/instance_agent/plugins/codedeploy/installer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def generate_instructions(application_specification)
6464
fi.source)
6565

6666
log(:debug, "generating instructions for copying #{fi.source} to #{fi.destination}")
67-
if File.directory?(absolute_source_path)
67+
if File.directory?(absolute_source_path) && !File.symlink?(absolute_source_path)
6868
fill_in_missing_ancestors(i, fi.destination)
6969
generate_directory_copy(i, absolute_source_path, fi.destination)
7070
else
@@ -108,7 +108,8 @@ def generate_directory_copy(i, absolute_source_path, destination)
108108
absolute_source_path = absolute_source_path.force_encoding("UTF-8");
109109
absolute_entry_path = File.join(absolute_source_path, entry)
110110
entry_destination = File.join(destination, entry)
111-
if File.directory?(absolute_entry_path)
111+
112+
if File.directory?(absolute_entry_path) && !File.symlink?(absolute_entry_path)
112113
generate_directory_copy(i, absolute_entry_path, entry_destination)
113114
else
114115
generate_normal_copy(i, absolute_entry_path, entry_destination)

test/instance_agent/plugins/codedeploy/installer_test.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,93 @@ class CodeDeployPluginInstallerTest < InstanceAgentTestCase
255255

256256
end # "regular files"
257257

258+
context "symbolic links" do
259+
260+
setup do
261+
@app_spec
262+
.stubs(:files)
263+
.returns([stub(:source => "src1",
264+
:destination => "dst1")])
265+
266+
File.stubs(:directory?).returns(false)
267+
File.stubs(:directory?).with("dst1").returns(true)
268+
269+
File.stubs(:exists?).returns(false)
270+
File.stubs(:exists?).with("dst1").returns(true)
271+
272+
@command_sequence = sequence("commands")
273+
end
274+
275+
should "generate a copy command for the source file if it is a symbolic link of a regular file" do
276+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(false)
277+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(true)
278+
279+
@instruction_builder
280+
.expects(:copy)
281+
.with("deploy-archive-dir/src1", "dst1/src1")
282+
.in_sequence(@command_sequence)
283+
284+
@installer.install(@deployment_group_id, @app_spec)
285+
end
286+
287+
should "generate a copy command instead of a mkdir command for the source file if it is a symbolic link of a directory" do
288+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
289+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(true)
290+
291+
@instruction_builder
292+
.expects(:mkdir)
293+
.with("dst1/src1")
294+
.never
295+
@instruction_builder
296+
.expects(:copy)
297+
.with("deploy-archive-dir/src1", "dst1/src1")
298+
.in_sequence(@command_sequence)
299+
300+
@installer.install(@deployment_group_id, @app_spec)
301+
end
302+
303+
should "generate a copy command if the file inside the source directory is a symbolic link of a regular file" do
304+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
305+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
306+
Dir.stubs(:entries)
307+
.with("deploy-archive-dir/src1")
308+
.returns([".", "..", "foo"])
309+
310+
File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(false)
311+
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)
312+
313+
@instruction_builder
314+
.expects(:copy)
315+
.with("deploy-archive-dir/src1/foo", "dst1/foo")
316+
.in_sequence(@command_sequence)
317+
318+
@installer.install(@deployment_group_id, @app_spec)
319+
end
320+
321+
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
322+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
323+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
324+
Dir.stubs(:entries)
325+
.with("deploy-archive-dir/src1")
326+
.returns([".", "..", "foo"])
327+
328+
File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(true)
329+
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)
330+
331+
@instruction_builder
332+
.expects(:mkdir)
333+
.with("dst1/foo")
334+
.never
335+
@instruction_builder
336+
.expects(:copy)
337+
.with("deploy-archive-dir/src1/foo", "dst1/foo")
338+
.in_sequence(@command_sequence)
339+
340+
@installer.install(@deployment_group_id, @app_spec)
341+
end
342+
343+
end # "symlinks"
344+
258345
context "directories" do
259346

260347
setup do

0 commit comments

Comments
 (0)