Add check_free_disk_space misc function (#10536)

* Add check_free_disk_space misc function

* Remove require 'matrix' line in misc_functions.rb
This commit is contained in:
Ed Reel
2024-09-28 13:38:30 -05:00
committed by GitHub
parent c78b28be9e
commit 24f8d4c2ef
5 changed files with 16 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
# lib/misc_functions.rb
# Generic implementations of various functions/algorithms that are not crew-specific.
require_relative 'color'
def require_gem(gem_name_and_require = nil, require_override = nil)
# Allow only loading gems when needed.
return if gem_name_and_require.nil?
@@ -91,4 +93,10 @@ class MiscFunctions
time_seconds_string = "#{time_seconds} second#{time_seconds == 1 ? '' : 's'}"
return time_hour_string + time_minutes_string + time_seconds_string
end
def self.check_free_disk_space(bytes = 0)
formatted_size = human_size(bytes)
free_space = `echo $(($(stat -f --format="%a*%S" #{CREW_PREFIX})))`.chomp.to_i
abort "\nNot enough free disk space. You need at least #{formatted_size} to install.\n".lightred if free_space < bytes
end
end