fix: prepare for evolution of (u)mount management
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build was killed

This commit is contained in:
Glenn Y. Rolland 2024-12-11 00:41:04 +01:00
parent 16b81ed038
commit a3d827bdb0
5 changed files with 37 additions and 35 deletions

View file

@ -8,18 +8,18 @@ require "../file_system_manager"
module GX::Commands module GX::Commands
class GlobalTui < AbstractCommand class GlobalTui < AbstractCommand
@file_system_manager : FileSystemManager # @file_system_manager : FileSystemManager
def initialize(@config : GX::Config) def initialize(@config : GX::Config)
@config.load_from_env @config.load_from_env
@config.load_from_file @config.load_from_file
@file_system_manager = FileSystemManager.new(@config) # @file_system_manager = FileSystemManager.new(@config)
end end
def execute def execute
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
@file_system_manager.mount_or_umount(filesystem) # @file_system_manager.mount_or_umount(filesystem)
@file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
end end
def self.handles_mode def self.handles_mode

View file

@ -36,7 +36,6 @@ module GX::Commands
@config.root.try do |root| @config.root.try do |root|
root.filesystems ||= [] of GX::Models::AbstractFilesystemConfig root.filesystems ||= [] of GX::Models::AbstractFilesystemConfig
root.filesystems << filesystem_config root.filesystems << filesystem_config
root.file_system_manager.mount_or_umount(filesystem_config)
end end
puts "Mapping '#{create_options.name}' created and added to configuration successfully." puts "Mapping '#{create_options.name}' created and added to configuration successfully."

View file

@ -8,7 +8,7 @@ require "../file_system_manager"
module GX::Commands module GX::Commands
class MappingMount < AbstractCommand class MappingMount < AbstractCommand
@file_system_manager : FileSystemManager # @file_system_manager : FileSystemManager
def initialize(@config : GX::Config) def initialize(@config : GX::Config)
@config.load_from_env @config.load_from_env
@ -16,14 +16,24 @@ module GX::Commands
end end
def execute def execute
filesystem = @config.root.try &.file_system_manager.choose_filesystem # filesystem = @config.root.try &.file_system_manager.choose_filesystem
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? # raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
filesystem.mount # filesystem.mount
@file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open? # @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
end end
def self.handles_mode def self.handles_mode
GX::Types::Mode::MappingMount GX::Types::Mode::MappingMount
end end
private def _mount_filesystem(filesystem : Models::AbstractFilesystemConfig)
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
if filesystem.mounted?
Log.info { "Filesystem already mounted." }
return
end
filesystem.mount
end
end end
end end

View file

@ -8,21 +8,33 @@ require "../file_system_manager"
module GX::Commands module GX::Commands
class MappingUmount < AbstractCommand class MappingUmount < AbstractCommand
@file_system_manager : FileSystemManager
def initialize(@config : GX::Config) def initialize(@config : GX::Config)
@config.load_from_env @config.load_from_env
@config.load_from_file @config.load_from_file
end end
def execute def execute
filesystem = @config.root.try &.file_system_manager.choose_filesystem # root = @config.root
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil? # raise "Missing root config" if root.nil?
filesystem.umount
# filesystem = root.file_system_manager.choose_filesystem
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# filesystem.umount
end end
def self.handles_mode def self.handles_mode
GX::Types::Mode::MappingUmount GX::Types::Mode::MappingUmount
end end
# OBSOLETE:
private def umount_filesystem(filesystem : Models::AbstractFilesystemConfig)
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
unless filesystem.mounted?
Log.info { "Filesystem is not mounted." }
return
end
filesystem.umount
end
end end
end end

View file

@ -13,25 +13,6 @@ module GX
def initialize(@config : Config) def initialize(@config : Config)
end end
# OBSOLETE:
# def mount_filesystem(filesystem : Models::AbstractFilesystemConfig)
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# if filesystem.mounted?
# Log.info { "Filesystem already mounted." }
# return
# end
# filesystem.mount
# end
# OBSOLETE:
# def umount_filesystem(filesystem : Models::AbstractFilesystemConfig)
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# unless filesystem.mounted?
# Log.info { "Filesystem is not mounted." }
# return
# end
# filesystem.umount
# end
def mount_or_umount(selected_filesystem) def mount_or_umount(selected_filesystem)
if !selected_filesystem.mounted? if !selected_filesystem.mounted?