From b1b94187af3dc4194721bc1a15bff1ec7a904eb6 Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Wed, 5 Apr 2023 03:25:59 +0800 Subject: [PATCH 1/4] tap: tighten `formula_file?(file)` Cask is never a formula. --- Library/Homebrew/tap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 3439ec0c92..fb09122cb7 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -570,7 +570,7 @@ class Tap file = file.expand_path(path) return false unless ruby_file?(file) - file.to_s.start_with?("#{formula_dir}/") + file.to_s.start_with?("#{formula_dir}/") && !file.to_s.start_with?("#{cask_dir}/") end # return true if given path would present a {Cask} file in this {Tap}. From 1098cb6a7d2ddb62302c1f09358c950c0fcdb006 Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Thu, 6 Apr 2023 04:59:55 +0800 Subject: [PATCH 2/4] avoid duplicating logic --- Library/Homebrew/tap.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index fb09122cb7..b96e878d0c 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -561,7 +561,7 @@ class Tap file.extname == ".rb" end - # return true if given path would present a {Formula} file in this {Tap}. + # returns true if given path would present a {Formula} file in this {Tap}. # accepts both absolute path and relative path (relative to this {Tap}'s path) # @private sig { params(file: T.any(String, Pathname)).returns(T::Boolean) } @@ -569,11 +569,12 @@ class Tap file = Pathname.new(file) unless file.is_a? Pathname file = file.expand_path(path) return false unless ruby_file?(file) + return false if cask_pathname?(file) - file.to_s.start_with?("#{formula_dir}/") && !file.to_s.start_with?("#{cask_dir}/") + file.to_s.start_with?("#{formula_dir}/") end - # return true if given path would present a {Cask} file in this {Tap}. + # returns true if given path would present a {Cask} file in this {Tap}. # accepts both absolute path and relative path (relative to this {Tap}'s path) # @private sig { params(file: T.any(String, Pathname)).returns(T::Boolean) } From 16c81d7a55b56519d3235c2e29290b7082b7ca72 Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Thu, 6 Apr 2023 05:00:21 +0800 Subject: [PATCH 3/4] tighten `tap.formula_files` similarly --- Library/Homebrew/tap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index b96e878d0c..54c6ce367c 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -498,7 +498,7 @@ class Tap formula_dir.find else formula_dir.children - end.select(&method(:ruby_file?)) + end.select(&method(:formula_file?)) else [] end From 0cfc4ab1e8bca66bbc08cae6b964a348e48116ec Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Thu, 6 Apr 2023 05:03:56 +0800 Subject: [PATCH 4/4] fixup! avoid duplicating logic --- Library/Homebrew/tap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 54c6ce367c..b7c12b5b20 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -569,7 +569,7 @@ class Tap file = Pathname.new(file) unless file.is_a? Pathname file = file.expand_path(path) return false unless ruby_file?(file) - return false if cask_pathname?(file) + return false if cask_file?(file) file.to_s.start_with?("#{formula_dir}/") end