Skip to content

Commit 5854945

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

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

lib/instance_agent/plugins/codedeploy/installer.rb

+3-2
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

+98
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,104 @@ 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 "not generate a copy command for the entries of 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+
Dir.stubs(:entries)
291+
.with("deploy-archive-dir/src1")
292+
.returns([".", "..", "foo"])
293+
294+
@instruction_builder
295+
.expects(:copy)
296+
.with("deploy-archive-dir/src1", "dst1/src1")
297+
.in_sequence(@command_sequence)
298+
@instruction_builder
299+
.expects(:copy)
300+
.with("deploy-archive-dir/src1/foo", "dst1/foo")
301+
.never
302+
303+
@installer.install(@deployment_group_id, @app_spec)
304+
end
305+
306+
should "generate a copy command if the file inside the source directory is a symbolic link of a regular file" do
307+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
308+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
309+
Dir.stubs(:entries)
310+
.with("deploy-archive-dir/src1")
311+
.returns([".", "..", "foo"])
312+
313+
File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(false)
314+
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)
315+
316+
@instruction_builder
317+
.expects(:copy)
318+
.with("deploy-archive-dir/src1/foo", "dst1/foo")
319+
.in_sequence(@command_sequence)
320+
321+
@installer.install(@deployment_group_id, @app_spec)
322+
end
323+
324+
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
325+
File.stubs(:directory?).with("deploy-archive-dir/src1").returns(true)
326+
File.stubs(:symlink?).with("deploy-archive-dir/src1").returns(false)
327+
Dir.stubs(:entries)
328+
.with("deploy-archive-dir/src1")
329+
.returns([".", "..", "foo"])
330+
331+
File.stubs(:directory?).with("deploy-archive-dir/src1/foo").returns(true)
332+
File.stubs(:symlink?).with("deploy-archive-dir/src1/foo").returns(true)
333+
Dir.stubs(:entries)
334+
.with("deploy-archive-dir/src1/foo")
335+
.returns([".", "..", "bar"])
336+
337+
338+
@instruction_builder
339+
.expects(:mkdir)
340+
.with("dst1/foo")
341+
.never
342+
@instruction_builder
343+
.expects(:copy)
344+
.with("deploy-archive-dir/src1/foo", "dst1/foo")
345+
.in_sequence(@command_sequence)
346+
@instruction_builder
347+
.expects(:copy)
348+
.with("deploy-archive-dir/src1/foo/bar", "dst1/foo/bar")
349+
.never
350+
351+
@installer.install(@deployment_group_id, @app_spec)
352+
end
353+
354+
end # "symlinks"
355+
258356
context "directories" do
259357

260358
setup do

0 commit comments

Comments
 (0)