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
class GlobalTui < AbstractCommand
@file_system_manager : FileSystemManager
# @file_system_manager : FileSystemManager
def initialize(@config : GX::Config)
@config.load_from_env
@config.load_from_file
@file_system_manager = FileSystemManager.new(@config)
# @file_system_manager = FileSystemManager.new(@config)
end
def execute
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
@file_system_manager.mount_or_umount(filesystem)
@file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# @file_system_manager.mount_or_umount(filesystem)
# @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
end
def self.handles_mode

View file

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

View file

@ -8,7 +8,7 @@ require "../file_system_manager"
module GX::Commands
class MappingMount < AbstractCommand
@file_system_manager : FileSystemManager
# @file_system_manager : FileSystemManager
def initialize(@config : GX::Config)
@config.load_from_env
@ -16,14 +16,24 @@ module GX::Commands
end
def execute
filesystem = @config.root.try &.file_system_manager.choose_filesystem
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
filesystem.mount
@file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
# filesystem = @config.root.try &.file_system_manager.choose_filesystem
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# filesystem.mount
# @file_system_manager.auto_open(filesystem) if filesystem.mounted? && @config.auto_open?
end
def self.handles_mode
GX::Types::Mode::MappingMount
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

View file

@ -8,21 +8,33 @@ require "../file_system_manager"
module GX::Commands
class MappingUmount < AbstractCommand
@file_system_manager : FileSystemManager
def initialize(@config : GX::Config)
@config.load_from_env
@config.load_from_file
end
def execute
filesystem = @config.root.try &.file_system_manager.choose_filesystem
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
filesystem.umount
# root = @config.root
# raise "Missing root config" if root.nil?
# filesystem = root.file_system_manager.choose_filesystem
# raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
# filesystem.umount
end
def self.handles_mode
GX::Types::Mode::MappingUmount
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

View file

@ -13,25 +13,6 @@ module GX
def initialize(@config : Config)
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)
if !selected_filesystem.mounted?