Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 7c87225

Browse files
committed
Ignore all symlinks
Porting the same behavior from [structure][0] and [builder][1] to this engine. [0]: https://github.com/codeclimate/codeclimate-structure/pull/305 [1]: https://github.com/codeclimate/builder/pull/1422
1 parent 8309212 commit 7c87225

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/cc/engine/analyzers/file_list.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ def initialize(engine_config:, patterns:)
1313

1414
def files
1515
engine_config.include_paths.flat_map do |path|
16-
if path.end_with?("/")
16+
pathname = Pathname.new(path)
17+
if pathname.directory? && !pathname.cleanpath.symlink?
1718
expand(path)
18-
elsif matches?(path)
19+
elsif pathname.file? && !pathname.symlink? && matches?(path)
1920
[path]
2021
else
2122
[]
@@ -30,11 +31,11 @@ def files
3031
def expand(path)
3132
globs = patterns.map { |p| File.join(relativize(path), p) }
3233

33-
Dir.glob(globs).select { |f| File.file?(f) }
34+
Dir.glob(globs).select { |f| File.file?(f) && !File.symlink?(f) }
3435
end
3536

3637
def matches?(path)
37-
File.file?(path) && patterns.any? do |p|
38+
patterns.any? do |p|
3839
File.fnmatch?(
3940
relativize(p),
4041
relativize(path),

spec/cc/engine/analyzers/file_list_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@
1515
File.write(File.join(@tmp_dir, "foo.jsx"), "")
1616
File.write(File.join(@tmp_dir, "foo.ex"), "")
1717

18-
example.run
18+
File.write("/tmp/bar.js", "")
19+
FileUtils.ln_s("/tmp/bar.js", File.join(@tmp_dir, "bar.js"))
20+
Dir.mkdir("/tmp/baz")
21+
File.write("/tmp/baz/baz.js", "")
22+
FileUtils.ln_s("/tmp/baz/", File.join(@tmp_dir, "baz"))
23+
24+
begin
25+
example.run
26+
ensure
27+
FileUtils.rm_rf(["/tmp/bar.js", "/tmp/baz"])
28+
end
1929
end
2030
end
2131
end
2232

2333
describe "#files" do
24-
it "expands patterns for directory includes" do
34+
it "expands patterns for directory includes, and ignores symlinks" do
2535
file_list = ::CC::Engine::Analyzers::FileList.new(
2636
engine_config: CC::Engine::Analyzers::EngineConfig.new(
2737
"include_paths" => ["./"],

0 commit comments

Comments
 (0)