class Aruba::Platforms::DetermineDiskUsage
Determinate disk usage
@private
Public Instance Methods
Source
# File lib/aruba/platforms/determine_disk_usage.rb, line 11 def call(paths) size = paths.flatten.sum { |path| minimum_disk_space_used path } FileSize.new(size) end
Private Instance Methods
Source
# File lib/aruba/platforms/determine_disk_usage.rb, line 49 def minimum_disk_space_used(path) # TODO: replace Aruba.config.physical_block_size # with something like Aruba.config.fs_allocation_unit dev_bsize = Aruba.config.physical_block_size stat = File::Stat.new(path.to_s) blocks = stat.blocks return blocks * dev_bsize if blocks typical_fs_unit = 4096 typical_dev_bsize = 512 # google dev_bsize for more info block_multiplier = typical_fs_unit / typical_dev_bsize fs_unit_size = dev_bsize * block_multiplier fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size fs_units = 1 if fs_units.zero? fs_units * fs_unit_size end
Report minimum disk space used
This estimates the minimum bytes allocated by the path.
E.g. a 1-byte text file on a typical EXT-3 filesystem takes up 4096 bytes (could be more if it was truncated or less for sparse files).
Both âFile::Stat` and the `stat()` system call will report 8 `blocks` (each âusuallyâ represents 512 bytes). So 8 * 512 is exactly 4096 bytes.
(The âmagicâ 512 bye implied makes the value of âblocksâ so confusing).
Currently Aruba allows you to set whatâs called the âphysical_block_size`, which is a bit misleading - itâs the â512â value. So if you somehow have a âfilesystem unit sizeâ of 8192 (instead of a typical 4KB), set the âphysical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
Ideally, Aruba should provide e.g. âAruba.config.fs_allocation_unit` (with 4096 as the default), so you wouldnât have to âdivide by 8â.
(typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
@return [Integer]
Total bytes allocate
TODO: this is recommended over the above âblocksâ