Skip to content

Commit b2fb194

Browse files
committed
Report exact sizes in the insufficient-disk-space error
Integer division truncated the GB figures (1.9 GB read as 1 GB), understating the requirement. Use number_to_human_size instead.
1 parent f942c93 commit b2fb194

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

app/models/account/import.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ def ensure_sufficient_disk_space
9696
available = available_disk_space(path)
9797

9898
if available && available < required
99-
raise InsufficientDiskSpaceError, "import needs ~#{required / 1.gigabyte} GB free, found #{available / 1.gigabyte} GB"
99+
raise InsufficientDiskSpaceError, "import needs ~#{human_size(required)} free, found #{human_size(available)}"
100100
end
101101
end
102102

103+
def human_size(bytes)
104+
ActiveSupport::NumberHelper.number_to_human_size(bytes)
105+
end
106+
103107
def available_disk_space(path)
104108
fields = `df -Pk #{Shellwords.escape(path)} 2>/dev/null`.lines.last.to_s.split
105109
# Anchor on the capacity percentage — the only NN% field — since spaces in

test/models/account/import_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Account::ImportTest < ActiveSupport::TestCase
225225
import.stubs(:available_disk_space).returns(import.file.blob.byte_size)
226226

227227
error = assert_raises(Account::Import::InsufficientDiskSpaceError) { import.check }
228-
assert_match(/GB free/, error.message)
228+
assert_match(/import needs ~.+ free, found/, error.message)
229229
assert import.reload.failed_due_to_insufficient_disk_space?
230230
end
231231

0 commit comments

Comments
 (0)