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

View File

@@ -1,4 +1,5 @@
require 'package'
require 'misc_functions'
class Android_studio < Package
description 'Android Studio is the official IDE for Android development.'
@@ -14,8 +15,7 @@ class Android_studio < Package
depends_on 'sommelier'
def self.preflight
free_space = `echo $(($(stat -f --format="%a*%S" #{CREW_PREFIX})))`.chomp.to_i
abort 'Not enough free disk space. You need at least 6 GB to install.'.lightred if free_space < 6442450944
MiscFunctions.check_free_disk_space(6442450944)
end
def self.install

View File

@@ -1,4 +1,5 @@
require 'package'
require 'misc_functions'
class Codelobster < Package
description 'Free cross-platform IDE for PHP/HTML/CSS/JavaScript development'
@@ -19,8 +20,7 @@ class Codelobster < Package
def self.preflight
abort 'Please remove qt5_base before installing.'.lightred if File.exist? "#{CREW_LIB_PREFIX}/libQt5Core.so.5"
free_space = `echo $(($(stat -f --format="%a*%S" .)))`.chomp.to_i
abort 'Not enough free disk space. You need at least 1.2 GB to install.'.lightred if free_space < 1288490188
MiscFunctions.check_free_disk_space(1288490188)
end
def self.patch

View File

@@ -1,4 +1,5 @@
require 'package'
require 'misc_functions'
class Freecad < Package
description 'A free and opensource multiplatform 3D parametric modeler.'
@@ -14,8 +15,7 @@ class Freecad < Package
depends_on 'sommelier'
def self.preflight
free_space = `echo $(($(stat -f --format="%a*%S" .)))`.chomp.to_i
abort 'Not enough free disk space. You need at least 5.2 GB to install.'.lightred if free_space < 5583457485
MiscFunctions.check_free_disk_space(5583457485)
end
def self.patch

View File

@@ -1,4 +1,5 @@
require 'package'
require 'misc_functions'
class Repo < Package
description 'The Multiple Git Repository Tool'
@@ -14,8 +15,7 @@ class Repo < Package
no_compile_needed
def self.preflight
free_space = `echo $(($(stat -f --format="%a*%S" #{CREW_PREFIX})))`.chomp.to_i
abort 'Not enough free disk space. You need at least 1 MB to install.'.lightred if free_space < 1000000
MiscFunctions.check_free_disk_space(1000000000)
end
def self.install