aruba 1.0.0.pre.alpha.5 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -28
  3. data/CONTRIBUTING.md +0 -9
  4. data/LICENSE +1 -1
  5. data/README.md +37 -30
  6. data/lib/aruba/api.rb +0 -1
  7. data/lib/aruba/api/bundler.rb +17 -2
  8. data/lib/aruba/api/commands.rb +15 -16
  9. data/lib/aruba/api/core.rb +64 -50
  10. data/lib/aruba/api/environment.rb +12 -4
  11. data/lib/aruba/api/filesystem.rb +32 -46
  12. data/lib/aruba/api/text.rb +15 -3
  13. data/lib/aruba/aruba_path.rb +23 -95
  14. data/lib/aruba/basic_configuration.rb +46 -65
  15. data/lib/aruba/basic_configuration/option.rb +2 -2
  16. data/lib/aruba/cli.rb +4 -1
  17. data/lib/aruba/config/jruby.rb +1 -1
  18. data/lib/aruba/config_wrapper.rb +17 -4
  19. data/lib/aruba/configuration.rb +29 -22
  20. data/lib/aruba/console.rb +0 -2
  21. data/lib/aruba/console/help.rb +8 -5
  22. data/lib/aruba/contracts/absolute_path.rb +3 -3
  23. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  24. data/lib/aruba/contracts/relative_path.rb +3 -3
  25. data/lib/aruba/cucumber/command.rb +93 -82
  26. data/lib/aruba/cucumber/file.rb +43 -23
  27. data/lib/aruba/cucumber/hooks.rb +4 -1
  28. data/lib/aruba/cucumber/testing_frameworks.rb +14 -12
  29. data/lib/aruba/event_bus.rb +4 -2
  30. data/lib/aruba/event_bus/name_resolver.rb +9 -8
  31. data/lib/aruba/events.rb +2 -1
  32. data/lib/aruba/hooks.rb +2 -4
  33. data/lib/aruba/in_config_wrapper.rb +8 -5
  34. data/lib/aruba/initializer.rb +9 -3
  35. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  36. data/lib/aruba/matchers/base/message_indenter.rb +1 -1
  37. data/lib/aruba/matchers/base/object_formatter.rb +0 -5
  38. data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
  39. data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -1
  40. data/lib/aruba/matchers/command/have_exit_status.rb +3 -1
  41. data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
  42. data/lib/aruba/matchers/command/have_output.rb +3 -1
  43. data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
  44. data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
  45. data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
  46. data/lib/aruba/matchers/file/have_file_size.rb +4 -2
  47. data/lib/aruba/matchers/path/have_permissions.rb +7 -4
  48. data/lib/aruba/platforms/announcer.rb +25 -11
  49. data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
  50. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
  51. data/lib/aruba/platforms/aruba_logger.rb +10 -9
  52. data/lib/aruba/platforms/command_monitor.rb +4 -6
  53. data/lib/aruba/platforms/determine_disk_usage.rb +55 -20
  54. data/lib/aruba/platforms/filesystem_status.rb +19 -13
  55. data/lib/aruba/platforms/simple_table.rb +2 -2
  56. data/lib/aruba/platforms/unix_environment_variables.rb +9 -4
  57. data/lib/aruba/platforms/unix_platform.rb +10 -10
  58. data/lib/aruba/platforms/unix_which.rb +1 -1
  59. data/lib/aruba/platforms/windows_command_string.rb +1 -1
  60. data/lib/aruba/platforms/windows_environment_variables.rb +2 -1
  61. data/lib/aruba/platforms/windows_platform.rb +3 -3
  62. data/lib/aruba/platforms/windows_which.rb +6 -2
  63. data/lib/aruba/processes/basic_process.rb +4 -6
  64. data/lib/aruba/processes/debug_process.rb +4 -2
  65. data/lib/aruba/processes/in_process.rb +5 -3
  66. data/lib/aruba/processes/spawn_process.rb +27 -16
  67. data/lib/aruba/rspec.rb +25 -15
  68. data/lib/aruba/runtime.rb +11 -4
  69. data/lib/aruba/setup.rb +23 -10
  70. data/lib/aruba/tasks/docker_helpers.rb +3 -1
  71. data/lib/aruba/version.rb +1 -1
  72. metadata +96 -109
  73. data/.cucumberproignore +0 -3
  74. data/.document +0 -5
  75. data/.github/ISSUE_TEMPLATE.md +0 -48
  76. data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
  77. data/.gitignore +0 -38
  78. data/.rspec +0 -3
  79. data/.rubocop.yml +0 -31
  80. data/.rubocop_todo.yml +0 -258
  81. data/.simplecov +0 -34
  82. data/.travis.yml +0 -73
  83. data/.yardopts +0 -11
  84. data/Dockerfile +0 -67
  85. data/Gemfile +0 -15
  86. data/Rakefile +0 -92
  87. data/TODO.md +0 -13
  88. data/appveyor.yml +0 -30
  89. data/aruba.gemspec +0 -46
  90. data/bin/console +0 -7
  91. data/bin/test +0 -9
  92. data/config/.gitignore +0 -1
  93. data/cucumber.yml +0 -6
  94. data/docker-compose.yml +0 -26
  95. data/fixtures/cli-app/.gitignore +0 -9
  96. data/fixtures/cli-app/.rspec +0 -2
  97. data/fixtures/cli-app/README.md +0 -39
  98. data/fixtures/cli-app/Rakefile +0 -1
  99. data/fixtures/cli-app/bin/aruba-test-cli +0 -6
  100. data/fixtures/cli-app/cli-app.gemspec +0 -25
  101. data/fixtures/cli-app/features/support/aruba.rb +0 -1
  102. data/fixtures/cli-app/features/support/env.rb +0 -1
  103. data/fixtures/cli-app/lib/cli/app.rb +0 -9
  104. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
  105. data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
  106. data/fixtures/cli-app/script/console +0 -14
  107. data/fixtures/cli-app/spec/spec_helper.rb +0 -7
  108. data/fixtures/cli-app/spec/support/aruba.rb +0 -1
  109. data/fixtures/copy/file.txt +0 -1
  110. data/fixtures/empty-app/.gitignore +0 -9
  111. data/fixtures/empty-app/.rspec +0 -2
  112. data/fixtures/empty-app/README.md +0 -24
  113. data/fixtures/empty-app/Rakefile +0 -1
  114. data/fixtures/empty-app/cli-app.gemspec +0 -25
  115. data/fixtures/empty-app/lib/cli/app.rb +0 -7
  116. data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
  117. data/fixtures/getting-started-app/.gitignore +0 -4
  118. data/fixtures/getting-started-app/Gemfile +0 -4
  119. data/fixtures/getting-started-app/README.md +0 -3
  120. data/fixtures/getting-started-app/features/support/env.rb +0 -1
  121. data/lib/aruba/extensions/string/strip.rb +0 -25
  122. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
@@ -10,7 +10,7 @@ module Aruba
10
10
  def indent_multiline_message(message)
11
11
  message = message.sub(/\n+\z/, '')
12
12
  message.lines.map do |line|
13
- line =~ /\S/ ? ' ' + line : line
13
+ /\S/.match?(line) ? " #{line}" : line
14
14
  end.join
15
15
  end
16
16
  end
@@ -12,9 +12,6 @@ module Aruba
12
12
  prepare_for_inspection(object).inspect
13
13
  end
14
14
 
15
- # rubocop:disable MethodLength
16
- # rubocop:disable Metrics/CyclomaticComplexity
17
-
18
15
  # @private
19
16
  # Prepares the provided object to be formatted by wrapping it as needed
20
17
  # in something that, when `inspect` is called on it, will produce the
@@ -47,8 +44,6 @@ module Aruba
47
44
 
48
45
  InspectableItem.new(inspection)
49
46
  end
50
- # rubocop:enable Metrics/CyclomaticComplexity
51
- # rubocop:enable MethodLength
52
47
 
53
48
  # @private
54
49
  def self.prepare_hash(input)
@@ -29,9 +29,7 @@ module Aruba
29
29
  # @api private
30
30
  # @return [String]
31
31
  def failure_message
32
- unless iterable?
33
- return "#{improve_hash_formatting(super)}, but was not iterable"
34
- end
32
+ return "#{improve_hash_formatting(super)}, but was not iterable" unless iterable?
35
33
 
36
34
  return failed_objects.first if failed_objects.size == 1
37
35
 
@@ -91,7 +89,9 @@ module Aruba
91
89
 
92
90
  def failure_message_for_item(index, failure_message)
93
91
  failure_message = indent_multiline_message(add_new_line_if_needed(failure_message))
94
- indent_multiline_message("object at index #{index} failed to match:#{failure_message}")
92
+ indent_multiline_message(
93
+ "object at index #{index} failed to match:#{failure_message}"
94
+ )
95
95
  end
96
96
 
97
97
  def add_new_line_if_needed(message)
@@ -29,7 +29,9 @@ RSpec::Matchers.define :be_successfully_executed do
29
29
  end
30
30
 
31
31
  failure_message do |_actual|
32
- "Expected `#{@actual}` to succeed but got non-zero exit status and the following output:\n\n#{@old_actual.output}\n"
32
+ "Expected `#{@actual}` to succeed" \
33
+ ' but got non-zero exit status and the following output:' \
34
+ "\n\n#{@old_actual.output}\n"
33
35
  end
34
36
  end
35
37
 
@@ -23,7 +23,9 @@ RSpec::Matchers.define :have_exit_status do |expected|
23
23
  @old_actual.stop
24
24
  @actual = actual.exit_status
25
25
 
26
- raise "Expected #{@old_actual} to respond to #exit_status" unless @old_actual.respond_to? :exit_status
26
+ unless @old_actual.respond_to? :exit_status
27
+ raise "Expected #{@old_actual} to respond to #exit_status"
28
+ end
27
29
 
28
30
  values_match? expected, @actual
29
31
  end
@@ -24,7 +24,9 @@ RSpec::Matchers.define :have_finished_in_time do
24
24
  @old_actual = actual
25
25
  @actual = @old_actual.commandline
26
26
 
27
- raise "Expected #{@old_actual} to respond to #timed_out?" unless @old_actual.respond_to? :timed_out?
27
+ unless @old_actual.respond_to? :timed_out?
28
+ raise "Expected #{@old_actual} to respond to #timed_out?"
29
+ end
28
30
 
29
31
  @old_actual.stop
30
32
 
@@ -19,7 +19,9 @@ RSpec::Matchers.define :have_output do |expected|
19
19
  match do |actual|
20
20
  @old_actual = actual
21
21
 
22
- raise "Expected #{@old_actual} to respond to #output" unless @old_actual.respond_to? :output
22
+ unless @old_actual.respond_to? :output
23
+ raise "Expected #{@old_actual} to respond to #output"
24
+ end
23
25
 
24
26
  @old_actual.stop
25
27
 
@@ -17,7 +17,9 @@ RSpec::Matchers.define :have_output_on_stderr do |expected|
17
17
  match do |actual|
18
18
  @old_actual = actual
19
19
 
20
- raise "Expected #{@old_actual} to respond to #stderr" unless @old_actual.respond_to? :stderr
20
+ unless @old_actual.respond_to? :stderr
21
+ raise "Expected #{@old_actual} to respond to #stderr"
22
+ end
21
23
 
22
24
  @old_actual.stop
23
25
 
@@ -17,7 +17,9 @@ RSpec::Matchers.define :have_output_on_stdout do |expected|
17
17
  match do |actual|
18
18
  @old_actual = actual
19
19
 
20
- raise "Expected #{@old_actual} to respond to #stdout" unless @old_actual.respond_to? :stdout
20
+ unless @old_actual.respond_to? :stdout
21
+ raise "Expected #{@old_actual} to respond to #stdout"
22
+ end
21
23
 
22
24
  @old_actual.stop
23
25
 
@@ -23,7 +23,8 @@ require 'rspec/expectations/version'
23
23
  #
24
24
  # RSpec.describe do
25
25
  # it { expect('dir1.d').to have_sub_directory(['subdir.1.d', 'subdir.2.d']) }
26
- # it { expect(directories).to include a_directory_with_sub_directory(['subdir.1.d', 'subdir.2.d']) }
26
+ # it { expect(directories)
27
+ # . to include a_directory_with_sub_directory(['subdir.1.d', 'subdir.2.d']) }
27
28
  # end
28
29
  RSpec::Matchers.define :have_sub_directory do |expected|
29
30
  match do |actual|
@@ -40,11 +41,15 @@ RSpec::Matchers.define :have_sub_directory do |expected|
40
41
  diffable
41
42
 
42
43
  failure_message do |actual|
43
- format('expected that directory "%s" has the following sub-directories: %s.', actual.join(', '), expected)
44
+ format('expected that directory "%s" has the following sub-directories: %s.',
45
+ actual.join(', '),
46
+ expected)
44
47
  end
45
48
 
46
49
  failure_message_when_negated do |actual|
47
- format('expected that directory "%s" does not have the following sub-directories: %s.', actual.join(', '), expected)
50
+ format('expected that directory "%s" does not have the following sub-directories: %s.',
51
+ actual.join(', '),
52
+ expected)
48
53
  end
49
54
  end
50
55
 
@@ -34,11 +34,13 @@ RSpec::Matchers.define :have_file_size do |expected|
34
34
  end
35
35
 
36
36
  failure_message do |_actual|
37
- format('expected that file "%s" has size "%s", but has "%s"', @old_actual, @actual, @expected)
37
+ format('expected that file "%s" has size "%s", but has "%s"',
38
+ @old_actual, @actual, @expected)
38
39
  end
39
40
 
40
41
  failure_message_when_negated do |_actual|
41
- format('expected that file "%s" does not have size "%s", but has "%s"', @old_actual, @actual, @expected)
42
+ format('expected that file "%s" does not have size "%s", but has "%s"',
43
+ @old_actual, @actual, @expected)
42
44
  end
43
45
  end
44
46
 
@@ -39,9 +39,10 @@ RSpec::Matchers.define :have_permissions do |expected|
39
39
  @old_actual = actual
40
40
  @actual = permissions(expand_path(@old_actual))
41
41
 
42
- @expected = if expected.is_a? Integer
42
+ @expected = case expected
43
+ when Integer
43
44
  expected.to_s(8)
44
- elsif expected.is_a? String
45
+ when String
45
46
  expected.gsub(/^0*/, '')
46
47
  else
47
48
  expected
@@ -51,11 +52,13 @@ RSpec::Matchers.define :have_permissions do |expected|
51
52
  end
52
53
 
53
54
  failure_message do |_actual|
54
- format('expected that path "%s" has permissions "%s", but has "%s".', @old_actual, @expected, @actual)
55
+ format('expected that path "%s" has permissions "%s", but has "%s".',
56
+ @old_actual, @expected, @actual)
55
57
  end
56
58
 
57
59
  failure_message_when_negated do |_actual|
58
- format('expected that path "%s" does not have permissions "%s", but has "%s".', @old_actual, @expected, @actual)
60
+ format('expected that path "%s" does not have permissions "%s", but has "%s".',
61
+ @old_actual, @expected, @actual)
59
62
  end
60
63
  end
61
64
 
@@ -1,7 +1,7 @@
1
1
  require 'shellwords'
2
2
  require 'aruba/colorizer'
3
3
 
4
- Aruba::Colorizer.coloring = false if !STDOUT.tty? && !ENV.key?('AUTOTEST')
4
+ Aruba::Colorizer.coloring = false if !$stdout.tty? && !ENV.key?('AUTOTEST')
5
5
 
6
6
  # Aruba
7
7
  module Aruba
@@ -21,7 +21,9 @@ module Aruba
21
21
  #
22
22
  # before do
23
23
  # current_example = context.example
24
- # aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
24
+ # if current_example.metadata[:announce_my_channel]
25
+ # aruba.announcer.activate :my_channel
26
+ # end
25
27
  # end
26
28
  #
27
29
  # Aruba.announcer.announce(:my_channel, 'my message')
@@ -80,25 +82,37 @@ module Aruba
80
82
 
81
83
  def after_init
82
84
  output_format :changed_configuration, proc { |n, v| format('# %s = %s', n, v) }
83
- output_format :changed_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
85
+ output_format :changed_environment,
86
+ proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
84
87
  output_format :command, '$ %s'
85
88
  output_format :directory, '$ cd %s'
86
- output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
87
- output_format :full_environment, proc { |h| format("<<-ENVIRONMENT\n%s\nENVIRONMENT", Aruba.platform.simple_table(h)) }
88
- output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
89
+ output_format :environment,
90
+ proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
91
+ output_format :full_environment,
92
+ proc { |h|
93
+ format("<<-ENVIRONMENT\n%s\nENVIRONMENT",
94
+ Aruba.platform.simple_table(h))
95
+ }
96
+ output_format :modified_environment,
97
+ proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
89
98
  output_format :stderr, "<<-STDERR\n%s\nSTDERR"
90
99
  output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
91
100
  output_format :command_content, "<<-COMMAND\n%s\nCOMMAND"
92
- output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
101
+ output_format :stop_signal,
102
+ proc { |p, s|
103
+ format('Command will be stopped with `kill -%s %s`', s, p)
104
+ }
93
105
  output_format :timeout, '# %s-timeout: %s seconds'
94
106
  output_format :wait_time, '# %s: %s seconds'
95
- output_format :command_filesystem_status, proc { |status|
96
- format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS",
97
- Aruba.platform.simple_table(status.to_h, sort: false)) }
107
+ output_format :command_filesystem_status,
108
+ proc { |status|
109
+ format("<<-COMMAND FILESYSTEM STATUS\n%s\nCOMMAND FILESYSTEM STATUS",
110
+ Aruba.platform.simple_table(status.to_h, sort: false))
111
+ }
98
112
  end
99
113
 
100
114
  def output_format(channel, string = '%s', &block)
101
- output_formats[channel.to_sym] = if block_given?
115
+ output_formats[channel.to_sym] = if block
102
116
  block
103
117
  elsif string.is_a?(Proc)
104
118
  string
@@ -18,7 +18,9 @@ module Aruba
18
18
  # @param [Boolean] check_presence (false)
19
19
  # Check if file exist
20
20
  def call(path, content, check_presence = false)
21
- fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path)
21
+ if check_presence && !Aruba.platform.file?(path)
22
+ raise "Expected #{path} to be present"
23
+ end
22
24
 
23
25
  Aruba.platform.mkdir(File.dirname(path))
24
26
 
@@ -22,11 +22,16 @@ module Aruba
22
22
  # @param [Boolean] check_presence (false)
23
23
  # Check if file exist
24
24
  def call(path, size, check_presence)
25
- fail "Expected #{path} to be present" if check_presence && !Aruba.platform.file?(path)
25
+ if check_presence && !Aruba.platform.file?(path)
26
+ raise "Expected #{path} to be present"
27
+ end
26
28
 
27
29
  Aruba.platform.mkdir(File.dirname(path))
28
30
 
29
- File.open(path, 'wb') { |f| f.seek(size - 1); f.write("\0") }
31
+ File.open(path, 'wb') do |f|
32
+ f.seek(size - 1)
33
+ f.write("\0")
34
+ end
30
35
 
31
36
  self
32
37
  end
@@ -47,20 +47,21 @@ module Aruba
47
47
  def logger
48
48
  l = ::Logger.new($stderr)
49
49
 
50
- case mode
51
- when :debug
52
- l.level = ::Logger::DEBUG
50
+ if mode == :debug
53
51
  format_debug(l)
54
- when :silent
55
- l.level = 9_999
56
- when :info
57
- l.level = ::Logger::INFO
58
- format_standard(l)
59
52
  else
60
- l.level = ::Logger::INFO
61
53
  format_standard(l)
62
54
  end
63
55
 
56
+ l.level = case mode
57
+ when :debug
58
+ ::Logger::DEBUG
59
+ when :silent
60
+ 9_999
61
+ else
62
+ ::Logger::INFO
63
+ end
64
+
64
65
  l
65
66
  end
66
67
 
@@ -12,7 +12,7 @@ module Aruba
12
12
 
13
13
  public
14
14
 
15
- attr_reader :registered_commands, :last_command_started
15
+ attr_reader :registered_commands, :last_command_started, :last_command_stopped
16
16
 
17
17
  class DefaultLastCommandStopped
18
18
  def nil?
@@ -20,7 +20,7 @@ module Aruba
20
20
  end
21
21
 
22
22
  def method_missing(*)
23
- fail NoCommandHasBeenStoppedError, 'No last command stopped available'
23
+ raise NoCommandHasBeenStoppedError, 'No last command stopped available'
24
24
  end
25
25
 
26
26
  def respond_to_missing?(*)
@@ -34,7 +34,7 @@ module Aruba
34
34
  end
35
35
 
36
36
  def method_missing(*)
37
- fail NoCommandHasBeenStartedError, 'No last command started available'
37
+ raise NoCommandHasBeenStartedError, 'No last command started available'
38
38
  end
39
39
 
40
40
  def respond_to_missing?(*)
@@ -52,8 +52,6 @@ module Aruba
52
52
  raise ArgumentError, e.message
53
53
  end
54
54
 
55
- attr_reader :last_command_stopped
56
-
57
55
  # Set last command started
58
56
  #
59
57
  # @param [String] cmd
@@ -78,7 +76,7 @@ module Aruba
78
76
  cmd = cmd.commandline if cmd.respond_to? :commandline
79
77
  command = registered_commands.reverse.find { |c| c.commandline == cmd }
80
78
 
81
- fail CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil?
79
+ raise CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil?
82
80
 
83
81
  command
84
82
  end
@@ -1,33 +1,68 @@
1
- require 'aruba/platforms/disk_usage_calculator'
1
+ require 'aruba/file_size'
2
2
 
3
- # Aruba
4
3
  module Aruba
5
- # Platforms
6
4
  module Platforms
7
5
  # Determinate disk usage
8
6
  #
9
7
  # @private
10
8
  class DetermineDiskUsage
11
- def call(*args)
12
- args = args.flatten
13
-
14
- deprecated_block_size = args.pop
15
- paths = args
16
-
17
- size = paths.flatten.map do |p|
18
- # TODO: replace the `call` methods signature so that you can use just
19
- # p.minimum_disk_space_used
20
- #
21
- # (Same result, since the values are multiplied, so
22
- # deprecated_block_size is canceled out
23
- DiskUsageCalculator.new.call(
24
- (p.minimum_disk_space_used / deprecated_block_size),
25
- deprecated_block_size
26
- )
27
- end.inject(0, &:+)
9
+ def call(paths)
10
+ size = paths.flatten.sum { |path| minimum_disk_space_used path }
28
11
 
29
12
  FileSize.new(size)
30
13
  end
14
+
15
+ private
16
+
17
+ # TODO: Aruba.config.physical_block_size could be allowed to be nil
18
+ # (So the unit size can be autodetected)
19
+
20
+ # Report minimum disk space used
21
+ #
22
+ # This estimates the minimum bytes allocated by the path.
23
+ #
24
+ # E.g. a 1-byte text file on a typical EXT-3 filesystem takes up 4096 bytes
25
+ # (could be more if it was truncated or less for sparse files).
26
+ #
27
+ # Both `File::Stat` and the `stat()` system call will report 8 `blocks`
28
+ # (each "usually" represents 512 bytes). So 8 * 512 is exactly 4096 bytes.
29
+ #
30
+ # (The "magic" 512 bye implied makes the value of "blocks" so confusing).
31
+ #
32
+ # Currently Aruba allows you to set what's called the `physical_block_size`,
33
+ # which is a bit misleading - it's the "512" value. So if you somehow have a
34
+ # "filesystem unit size" of 8192 (instead of a typical 4KB), set the
35
+ # `physical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
36
+ #
37
+ # Ideally, Aruba should provide e.g. `Aruba.config.fs_allocation_unit`
38
+ # (with 4096 as the default), so you wouldn't have to "divide by 8".
39
+ #
40
+ # (typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
41
+ #
42
+ #
43
+ # @return [Integer]
44
+ # Total bytes allocate
45
+ #
46
+ # TODO: this is recommended over the above "blocks"
47
+ def minimum_disk_space_used(path)
48
+ # TODO: replace Aruba.config.physical_block_size
49
+ # with something like Aruba.config.fs_allocation_unit
50
+ dev_bsize = Aruba.config.physical_block_size
51
+
52
+ stat = File::Stat.new(path.to_s)
53
+
54
+ blocks = stat.blocks
55
+ return (blocks * dev_bsize) if blocks
56
+
57
+ typical_fs_unit = 4096
58
+ typical_dev_bsize = 512 # google dev_bsize for more info
59
+
60
+ block_multiplier = typical_fs_unit / typical_dev_bsize
61
+ fs_unit_size = dev_bsize * block_multiplier
62
+ fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size
63
+ fs_units = 1 if fs_units.zero?
64
+ fs_units * fs_unit_size
65
+ end
31
66
  end
32
67
  end
33
68
  end