From dbed4628e059ff7fcece3502634b00e017e2f857 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 27 Dec 2014 08:55:06 -0500 Subject: [PATCH] move cabv method out of Pathname monkeypatch recast as utility method --- lib/cask/cli/info.rb | 2 +- lib/cask/installer.rb | 2 +- lib/cask/utils.rb | 30 ++++++++++++++---------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/cask/cli/info.rb b/lib/cask/cli/info.rb index 7c9a000b86ca2..c9b2c636cc420 100644 --- a/lib/cask/cli/info.rb +++ b/lib/cask/cli/info.rb @@ -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 diff --git a/lib/cask/installer.rb b/lib/cask/installer.rb index 340913e94b7d6..976c93caaa648 100644 --- a/lib/cask/installer.rb +++ b/lib/cask/installer.rb @@ -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 diff --git a/lib/cask/utils.rb b/lib/cask/utils.rb index 53710e11785bb..14431aba9b285 100644 --- a/lib/cask/utils.rb +++ b/lib/cask/utils.rb @@ -40,22 +40,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() @@ -169,6 +153,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)