Class: Homebrew::DevCmd::AdvisoryMatch::DirEmitter Private
- Defined in:
- dev-cmd/advisory-match.rb
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Instance Method Summary collapse
- #<<(record) ⇒ void private
- #existing_source(path) ⇒ String? private
- #finish ⇒ void private
- #initialize(dir, verbose:) ⇒ void constructor private
Constructor Details
#initialize(dir, verbose:) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
154 155 156 157 158 159 160 161 162 |
# File 'dev-cmd/advisory-match.rb', line 154 def initialize(dir, verbose:) super() FileUtils.mkdir_p(dir) @dir = dir @verbose = verbose @written = T.let(0, Integer) @unchanged = T.let(0, Integer) @skipped_generated = T.let(0, Integer) end |
Instance Method Details
#<<(record) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'dev-cmd/advisory-match.rb', line 165 def <<(record) path = File.join(@dir, "#{record.fetch(:id)}.json") # A record already emitted by `generate-vulns-advisories` (a formula # `resolves` patch annotation) is more authoritative than a matched # candidate; overwriting it would drop `fix: "patch"` for a derived # `fix: null`/`"bump"`. if File.file?(path) && existing_source(path) == "generated" @skipped_generated += 1 return end merged = Homebrew::Vulns::OsvExport.merge_existing(path, record) if merged.nil? @unchanged += 1 return end File.write(path, "#{JSON.pretty_generate(merged)}\n") puts " wrote #{path}" if @verbose @written += 1 end |
#existing_source(path) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
186 187 188 189 190 |
# File 'dev-cmd/advisory-match.rb', line 186 def existing_source(path) JSON.parse(File.read(path)).dig("database_specific", "source") rescue JSON::ParserError nil end |
#finish ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
193 194 195 196 |
# File 'dev-cmd/advisory-match.rb', line 193 def finish Utils::Output.ohai "#{@written} records written to #{@dir} " \ "(#{@unchanged} unchanged, #{@skipped_generated} generated left as-is)" end |