2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-04 02:05:17 -05:00
|
|
|
class DiskSpace
|
|
|
|
def self.uploads_used_bytes
|
2015-02-04 05:37:02 -05:00
|
|
|
# used(uploads_path)
|
|
|
|
# temporary (on our internal setup its just too slow to iterate)
|
|
|
|
Upload.sum(:filesize).to_i
|
2015-02-04 02:05:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.uploads_free_bytes
|
2015-02-04 05:37:02 -05:00
|
|
|
free(uploads_path)
|
2015-02-04 02:05:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.free(path)
|
2016-01-24 21:22:36 -05:00
|
|
|
`df -Pk #{path} | awk 'NR==2 {print $4;}'`.to_i * 1024
|
2015-02-04 02:05:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.used(path)
|
2016-01-24 21:03:25 -05:00
|
|
|
`du -s #{path}`.to_i * 1024
|
2015-02-04 02:05:17 -05:00
|
|
|
end
|
2018-12-14 17:14:46 -05:00
|
|
|
|
|
|
|
def self.uploads_path
|
|
|
|
"#{Rails.root}/public/uploads/#{RailsMultisite::ConnectionManagement.current_db}"
|
|
|
|
end
|
|
|
|
private_class_method :uploads_path
|
2015-02-04 02:05:17 -05:00
|
|
|
end
|