aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
diff options
context:
space:
mode:
authorXu Cheng2016-04-01 11:08:29 +0800
committerXu Cheng2016-04-01 16:30:14 +0800
commit91fd357c90a29dfb974d5e465d3236771c1e60f9 (patch)
treee1af9fda2767e26a2d78a6dd7ac908e68f266c5d /Library/Homebrew/extend
parent028d155e97014076adf4e4dbc7c888fd871de321 (diff)
downloadbrew-91fd357c90a29dfb974d5e465d3236771c1e60f9.tar.bz2
Pathname: improve compute_disk_usage
* Count .DS_Store disk usage but not file count. * Count symlink's own disk usage instead of ignoring it. * Count hardlinks disk usage only once. * Add testcase. Closes Homebrew/homebrew#50563. Closes Homebrew/homebrew#50566. Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library/Homebrew/extend')
-rw-r--r--Library/Homebrew/extend/pathname.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 284dc85f8..fbd7b53d1 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -27,17 +27,27 @@ module DiskUsageExtension
def compute_disk_usage
if directory?
+ scanned_files = Set.new
@file_count = 0
@disk_usage = 0
find do |f|
- if !f.directory? && !f.symlink? && f.basename.to_s != ".DS_Store"
- @file_count += 1
- @disk_usage += f.size
+ if f.directory?
+ @disk_usage += f.lstat.size
+ else
+ @file_count += 1 if f.basename.to_s != ".DS_Store"
+ # use Pathname#lstat instead of Pathname#stat to get info of symlink itself.
+ stat = f.lstat
+ file_id = [stat.dev, stat.ino]
+ # count hardlinks only once.
+ unless scanned_files.include?(file_id)
+ @disk_usage += stat.size
+ scanned_files.add(file_id)
+ end
end
end
else
@file_count = 1
- @disk_usage = size
+ @disk_usage = lstat.size
end
end
end