Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move cabv method out of Pathname monkeypatch #8460

Merged
merged 1 commit into from
Dec 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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()
Expand Down Expand Up @@ -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)
Expand Down