Pathname#abv: handle the case du returns empty string

This can happen when read permission is denied.

Fixes Homebrew/homebrew#41925.

Closes Homebrew/homebrew#42011.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Xu Cheng 2015-07-22 19:47:02 +08:00
parent ebd0f34561
commit fd7f3b9496

View File

@ -393,7 +393,9 @@ class Pathname
out = ""
n = Utils.popen_read("find", expand_path.to_s, "-type", "f", "!", "-name", ".DS_Store").split("\n").size
out << "#{n} files, " if n > 1
out << Utils.popen_read("/usr/bin/du", "-hs", expand_path.to_s).split("\t")[0].strip
size = Utils.popen_read("/usr/bin/du", "-hs", expand_path.to_s).split("\t")[0]
size ||= "0B"
out << size.strip
out
end