2023-11-24 00:20:16 +01:00
|
|
|
module GX::Models::Concerns
|
|
|
|
module Base
|
2024-01-14 20:31:38 +01:00
|
|
|
def mounted? : Bool
|
2023-11-24 00:20:16 +01:00
|
|
|
mount_point_safe = @mount_point
|
2023-11-24 10:25:30 +01:00
|
|
|
raise InvalidMountpointError.new("Invalid mountpoint value") if mount_point_safe.nil?
|
2023-11-24 00:20:16 +01:00
|
|
|
|
|
|
|
`mount`.includes?(" on #{mount_point_safe} type ")
|
|
|
|
end
|
|
|
|
|
2024-01-14 20:31:38 +01:00
|
|
|
def umount : Nil
|
2023-11-24 00:20:16 +01:00
|
|
|
mount_point_safe = @mount_point
|
2023-11-24 10:25:30 +01:00
|
|
|
raise InvalidMountpointError.new("Invalid mountpoint value") if mount_point_safe.nil?
|
2023-11-24 00:20:16 +01:00
|
|
|
|
|
|
|
system("fusermount -u #{mount_point_safe.shellescape}")
|
|
|
|
fusermount_status = $?
|
|
|
|
|
|
|
|
if fusermount_status.success?
|
|
|
|
puts "Models #{name} is now closed.".colorize(:green)
|
|
|
|
else
|
|
|
|
puts "Error: Unable to unmount filesystem #{name} (exit code: #{fusermount_status.exit_code}).".colorize(:red)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-14 20:31:38 +01:00
|
|
|
def mount_point?
|
2023-11-24 00:20:16 +01:00
|
|
|
!mount_point.nil?
|
|
|
|
end
|
|
|
|
|
2024-01-14 20:31:38 +01:00
|
|
|
def mount
|
2023-11-24 00:20:16 +01:00
|
|
|
_mount_wrapper() do
|
|
|
|
_mount_action
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _mount_wrapper(&block) : Nil
|
|
|
|
mount_point_safe = mount_point
|
|
|
|
return if mount_point_safe.nil?
|
|
|
|
|
|
|
|
Dir.mkdir_p(mount_point_safe) unless Dir.exists?(mount_point_safe)
|
|
|
|
if mounted?
|
|
|
|
puts "Already mounted. Skipping.".colorize(:yellow)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-11-24 19:25:21 +01:00
|
|
|
result_status = yield
|
2023-11-24 00:20:16 +01:00
|
|
|
|
2023-11-24 19:25:21 +01:00
|
|
|
if result_status.success?
|
|
|
|
puts "Models #{name} is now available on #{mount_point_safe}".colorize(:green)
|
|
|
|
else
|
|
|
|
puts "Error mounting the vault".colorize(:red)
|
|
|
|
return
|
|
|
|
end
|
2023-11-24 00:20:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|