2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-04 15:05:17 +08:00
|
|
|
class DiskSpace
|
|
|
|
def self.uploads_used_bytes
|
2015-02-04 18:37:02 +08:00
|
|
|
# used(uploads_path)
|
|
|
|
# temporary (on our internal setup its just too slow to iterate)
|
|
|
|
Upload.sum(:filesize).to_i
|
2015-02-04 15:05:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.uploads_free_bytes
|
2015-02-04 18:37:02 +08:00
|
|
|
free(uploads_path)
|
2015-02-04 15:05:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.free(path)
|
2020-02-18 12:13:09 +08:00
|
|
|
output = Discourse::Utils.execute_command('df', '-Pk', path)
|
|
|
|
size_line = output.split("\n")[1]
|
|
|
|
size_line.split(/\s+/)[3].to_i * 1024
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.percent_free(path)
|
|
|
|
output = Discourse::Utils.execute_command('df', '-P', path)
|
|
|
|
size_line = output.split("\n")[1]
|
|
|
|
size_line.split(/\s+/)[4].to_i
|
2015-02-04 15:05:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.used(path)
|
2020-02-18 12:13:09 +08:00
|
|
|
Discourse::Utils.execute_command("du", "-s", path).to_i * 1024
|
2015-02-04 15:05:17 +08:00
|
|
|
end
|
2018-12-15 06:14:46 +08:00
|
|
|
|
|
|
|
def self.uploads_path
|
2019-12-18 13:51:57 +08:00
|
|
|
"#{Rails.root}/public/#{Discourse.store.upload_path}"
|
2018-12-15 06:14:46 +08:00
|
|
|
end
|
|
|
|
private_class_method :uploads_path
|
2015-02-04 15:05:17 +08:00
|
|
|
end
|