move cabv method out of Pathname monkeypatch

recast as utility method
This commit is contained in:
Roland Walker 2014-12-27 08:55:06 -05:00
parent 88158f31c5
commit dbed4628e0
3 changed files with 16 additions and 18 deletions

View File

@ -16,7 +16,7 @@ class Cask::CLI::Info < Cask::CLI::Base
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

View File

@ -75,7 +75,7 @@ class Cask::Installer
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

View File

@ -40,22 +40,6 @@ class Hash
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 @@ module Cask::Utils
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)