Module: Boxlet::Util
- Includes:
- Sys
- Defined in:
- lib/boxlet/util.rb
Class Method Summary collapse
- .app_space_capacity ⇒ Object
- .app_space_usage ⇒ Object
- .base_upload_path(uuid) ⇒ Object
- .drive_capacity ⇒ Object
-
.drive_free_space ⇒ Object
Drive disk space functions.
-
.encrypt(string) ⇒ Object
Auth methods.
-
.free_space ⇒ Object
App disk space functions.
-
.user_upload_dir(uuid) ⇒ Object
Directory paths.
Class Method Details
.app_space_capacity ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/boxlet/util.rb', line 18 def self.app_space_capacity return -1 if Boxlet.config[:s3][:enabled] drive_free_space = Boxlet::Util.drive_free_space if Boxlet.config[:capacity].is_a?(String) Boxlet::Util.drive_free_space * Boxlet.config[:capacity].to_i / 100 else Boxlet.config[:capacity] end end |
.app_space_usage ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/boxlet/util.rb', line 28 def self.app_space_usage raise RuntimeError, "#{Boxlet.config[:upload_dir]} is not a directory" unless File.directory?(Boxlet.config[:upload_dir]) return -1 if Boxlet.config[:s3][:enabled] total_size = 0 Dir["#{Boxlet.config[:upload_dir]}/**/*"].each do |f| total_size += File.size(f) if File.file?(f) && File.size?(f) end total_size / 1000000 # / 1048576 # to megabytes rescue Exception => e Boxlet.log(:fatal, "ERROR: #{e}") end |
.base_upload_path(uuid) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/boxlet/util.rb', line 74 def self.base_upload_path(uuid) if Boxlet.config[:s3][:enabled] "https://s3.amazonaws.com/#{Boxlet.config[:s3][:bucket]}/#{uuid}" else "#{Boxlet.config[:public_url]}/#{Boxlet.config[:upload_dir]}/#{Digest::MD5.hexdigest(uuid)}".gsub('/./', '/') end end |
.drive_capacity ⇒ Object
47 48 49 50 |
# File 'lib/boxlet/util.rb', line 47 def self.drive_capacity stat = Filesystem.stat(Boxlet.config[:file_system_root]) (stat.block_size * stat.blocks).to_mb end |
.drive_free_space ⇒ Object
Drive disk space functions
42 43 44 45 |
# File 'lib/boxlet/util.rb', line 42 def self.drive_free_space stat = Filesystem.stat(Boxlet.config[:file_system_root]) (stat.block_size * stat.blocks_available).to_mb end |
.encrypt(string) ⇒ Object
Auth methods
8 9 10 |
# File 'lib/boxlet/util.rb', line 8 def self.encrypt(string) (Digest::SHA256.new << string).to_s end |
.free_space ⇒ Object
App disk space functions
13 14 15 16 |
# File 'lib/boxlet/util.rb', line 13 def self.free_space return -1 if Boxlet.config[:s3][:enabled] Boxlet::Util.app_space_capacity - Boxlet::Util.app_space_usage end |
.user_upload_dir(uuid) ⇒ Object
Directory paths
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/boxlet/util.rb', line 53 def self.user_upload_dir(uuid) dir_name = uuid || '' user_upload_dir_name = Boxlet.config[:upload_dir] + "/" + dir_name Dir.mkdir(user_upload_dir_name) unless File.exists?(user_upload_dir_name) if uuid dir_shortname = Digest::MD5.hexdigest(dir_name) user_upload_dir_shortname = Boxlet.config[:upload_dir] + "/" + dir_shortname File.symlink(dir_name, user_upload_dir_shortname) if !File.symlink? user_upload_dir_shortname if File.symlink?(user_upload_dir_shortname) user_upload_dir_shortname else user_upload_dir_name end else user_upload_dir_name end end |