Skip to content

Commit

Permalink
Merge pull request #8460 from rolandwalker/no_monkeypatch_cabv
Browse files Browse the repository at this point in the history
move `cabv` method out of `Pathname` monkeypatch
  • Loading branch information
rolandwalker committed Dec 27, 2014
2 parents 9585cd1 + dbed462 commit dfe6307
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/cask/cli/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.help

def self.info(cask)
installation = if cask.installed?
"#{cask.staged_path} (#{cask.staged_path.cabv})"
"#{cask.staged_path} (#{Cask::Utils.cabv(cask.staged_path)})"
else
"Not installed"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def summary
else
"#{Tty.blue.bold}==>#{Tty.white} Success!#{Tty.reset} "
end
s << "#{@cask} staged at '#{@cask.staged_path}' (#{@cask.staged_path.cabv})"
s << "#{@cask} staged at '#{@cask.staged_path}' (#{Cask::Utils.cabv(@cask.staged_path)})"
end

def download
Expand Down
30 changes: 14 additions & 16 deletions lib/cask/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ def assert_valid_keys(*valid_keys)
end
end

# monkeypatch Pathname
class Pathname
# our own version of Homebrew's abv, with better defenses
# against unusual filenames
def cabv
out=''
n = Cask::SystemCommand.run!('/usr/bin/find',
:args => [self.realpath, *%w[-type f ! -name .DS_Store]],
:print_stderr => false).stdout.count("\n")
out << "#{n} files, " if n > 1
out << Cask::SystemCommand.run!('/usr/bin/du',
:args => ['-hs', '--', self.to_s],
:print_stderr => false).stdout.split("\t").first.strip
end
end

class Buffer < StringIO
def initialize(tty = false)
super()
Expand Down Expand Up @@ -162,6 +146,20 @@ def self.rmdir_if_possible(dir)
end
end

# our own version of Homebrew's abv, with better defenses
# against unusual filenames
def self.cabv(dir)
output = ''
count = Cask::SystemCommand.run!('/usr/bin/find',
:args => [dir, *%w[-type f -not -name .DS_Store -print0]],
:print_stderr => false).stdout.count("\000")
size = Cask::SystemCommand.run!('/usr/bin/du',
:args => ['-hs', '--', dir],
:print_stderr => false).stdout.split("\t").first.strip
output << "#{count} files, " if count > 1
output << size
end

# paths that "look" descendant (textually) will still
# return false unless both the given paths exist
def self.file_is_descendant(file, dir)
Expand Down

0 comments on commit dfe6307

Please sign in to comment.