Skip to content
Snippets Groups Projects
Commit 24224dc8 authored by Xu Cheng's avatar Xu Cheng
Browse files

pathname: improve compute_disk_usage

* Avoid parallel assignment.
* Use Pathname#size instead of File#size
* Use Pathname#directory? instead of File#directory?
* Use basename to check `.DS_Store`. Original regex has poor
  performance, and may match with incorrect file.
parent 482481d2
No related branches found
No related tags found
No related merge requests found
......@@ -27,11 +27,12 @@ module DiskUsageExtension
def compute_disk_usage
if self.directory?
@file_count, @disk_usage = [0, 0]
@file_count = 0
@disk_usage = 0
self.find do |f|
if !File.directory?(f) and !f.to_s.match(/\.DS_Store/)
if !f.directory? && f.basename.to_s != ".DS_Store"
@file_count += 1
@disk_usage += File.size(f)
@disk_usage += f.size
end
end
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment