Skip to content

Commit

Permalink
Improve plist handling for hdiutil commands
Browse files Browse the repository at this point in the history
- Raise `CaskError` instead of `Plist::ParseError` from module
- Improve error message when parse result is empty
- remove leading garbage text and emit it to stderr (seen in Homebrew#5060)
- remove trailing garbage text and emit it to stderr (seen in Homebrew#4819)

This has the incidental effect of emitting DMG licenses during
installation, which seems desirable as permanent functionality.

If not permanent, the warnings to STDERR should still be kept
temporarily to help get better bug reports on `hdiutil`.

A bug wrt DMG licenses must have been introduced in one of
Homebrew#4892, Homebrew#4887, Homebrew#4889, Homebrew#4900, Homebrew#4975, Homebrew#4978, or Homebrew#4857.  Presumably,
the cause is that STDERR was previously silenced when running
`hdiutil`.  It would be cleaner (and more reliable) to redirect
STDERR and examine it separately, rather than clean up the
merged outputs.

closes Homebrew#4819
closes Homebrew#5060
  • Loading branch information
rolandwalker committed Jun 25, 2014
1 parent 46cb834 commit deb7940
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/cask/system_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,30 @@ def self._assert_success(status, command, output)
end
end

def self._warn_plist_garbage(command, garbage)
return true unless garbage =~ %r{\S}
external = File.basename(command.first)
lines = garbage.strip.split("\n")
opoo "Non-XML output from #{external}:"
STDERR.puts lines.map {|l| " #{l}"}
end

def self._parse_plist(command, output)
begin
raise Plist::ParseError "Empty XML input" unless output =~ %r{\S}
raise CaskError.new("Empty plist input") unless output =~ %r{\S}
output.sub!(%r{\A(.*?)(<\?\s*xml)}m, '\2')
_warn_plist_garbage(command, $1)
output.sub!(%r{(<\s*/\s*plist\s*>)(.*?)\Z}m, '\1')
_warn_plist_garbage(command, $2)
xml = Plist::parse_xml(output)
unless xml.respond_to?(:keys) and xml.keys.size > 0
raise Plist::ParseError "Empty XML output"
raise CaskError.new(<<-ERRMSG)
Empty result parsing plist output from command.
command was:
#{command.utf8_inspect}
output we attempted to parse:
#{output}
ERRMSG
end
xml
rescue Plist::ParseError => e
Expand Down

0 comments on commit deb7940

Please sign in to comment.