1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-18 13:31:36 +03:00
mobile-nixos/boot/init/tasks/auto_resize.rb
Samuel Dionne-Riel d41c454514 boot/init: Add Devices dependency type
It's a Files dependency, but with just a bit more user friendliness when
used in an error message.
2020-11-07 20:13:31 -05:00

36 lines
1.2 KiB
Ruby

# Automatically resizes the given filesystem.
class Tasks::AutoResize < Task
attr_reader :device
def initialize(device, type: )
@device = device
@type = type
add_dependency(:Devices, @device)
end
def run()
log("Resizing #{@device}...")
if @type.match(/^ext[234]$/)
Progress.exec_with_message("Verifying #{@device}...") do
# TODO: Understand the actual underlying issue with e2fsck.
# It seems `e2fsck` succeeds, according to the output, but has a >0 exit
# status. Running it again in those situations is a no-op, which is weird
# to me.
# This is why we unconditionally run it once, then twice.
# The second will hopefully abort the boot if it fails too.
begin
System.run_long_running("e2fsck", "-fp", @device)
rescue System::CommandError
$logger.info("Re-running e2fsc...")
System.run_long_running("e2fsck", "-fp", @device)
end
end
Progress.exec_with_message("Resizing #{@device}...") do
System.run_long_running("resize2fs", "-f", @device)
end
else
$logger.warn("Cannot resize #{@type}... filesystem left untouched.")
end
end
end