mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: use DiskSpace module for all disk space calculations
This normalizes it so we only carry one place for grabbing disk space size It also normalizes the command made so it uses Discourse.execute_command which splits off params in a far cleaner way.
This commit is contained in:
@ -12,11 +12,19 @@ class DiskSpace
|
||||
end
|
||||
|
||||
def self.free(path)
|
||||
`df -Pk #{path} | awk 'NR==2 {print $4;}'`.to_i * 1024
|
||||
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
|
||||
end
|
||||
|
||||
def self.used(path)
|
||||
`du -s #{path}`.to_i * 1024
|
||||
Discourse::Utils.execute_command("du", "-s", path).to_i * 1024
|
||||
end
|
||||
|
||||
def self.uploads_path
|
||||
|
Reference in New Issue
Block a user