1
0
Fork 0
forked from glenux/mfm

feat: add support for more filesystems

This commit is contained in:
Glenn Y. Rolland 2023-10-24 17:04:15 +02:00
parent cef669e15e
commit 64528611dd
5 changed files with 61 additions and 4 deletions

View file

@ -69,8 +69,19 @@ module GX
names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String) names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String)
@config.filesystems.each do |filesystem| @config.filesystems.each do |filesystem|
result_name = filesystem.mounted? ? "#{filesystem.name} [open]" : filesystem.name fs_str = filesystem.type.ljust(12,' ')
ansi_name = filesystem.mounted? ? "#{filesystem.name} [#{ "open".colorize(:green) }]" : filesystem.name result_name =
if filesystem.mounted?
"#{fs_str} #{filesystem.name} [open]"
else
"#{fs_str} #{filesystem.name}"
end
ansi_name =
if filesystem.mounted?
"#{fs_str.colorize(:dark_gray)} #{filesystem.name} [#{ "open".colorize(:green) }]"
else
"#{fs_str.colorize(:dark_gray)} #{filesystem.name}"
end
names_display[result_name] = { names_display[result_name] = {
filesystem: filesystem, filesystem: filesystem,

View file

@ -1,3 +1,5 @@
require "./filesystems/gocryptfs" require "./filesystems/gocryptfs"
require "./filesystems/sshfs"
require "./filesystems/httpdirfs"
require "./filesystems/filesystem" require "./filesystems/filesystem"

View file

@ -8,7 +8,8 @@ module GX
use_yaml_discriminator "type", { use_yaml_discriminator "type", {
gocryptfs: GoCryptFS, gocryptfs: GoCryptFS,
sshfs: SshFS sshfs: SshFS,
httpdirfs: HttpDirFS
} }
property type : String property type : String

View file

@ -13,7 +13,7 @@ module GX
def after_initialize() def after_initialize()
home_dir = ENV["HOME"] || raise "Home directory not found" home_dir = ENV["HOME"] || raise "Home directory not found"
@mount_dir = File.join(home_dir, "mnt/#{@name}") @mount_dir = File.join(home_dir, "mnt/#{@name}.Open")
end end
def mounted? : Bool def mounted? : Bool

View file

@ -0,0 +1,43 @@
require "shellwords"
require "./filesystem"
module GX
class HttpDirFS < Filesystem
getter name : String = ""
getter url : String = ""
@[YAML::Field(key: "mount_dir", ignore: true)]
getter mount_dir : String = ""
include GenericFilesystem
def after_initialize()
home_dir = ENV["HOME"] || raise "Home directory not found"
@mount_dir = File.join(home_dir, "mnt/#{@name}")
end
def mounted? : Bool
`mount`.includes?("httpdirfs on #{mount_dir}")
end
def mount
super do
input = STDIN
output = STDOUT
error = STDERR
process = Process.new(
"httpdirfs",
["#{url}", mount_dir],
input: input,
output: output,
error: error
)
unless process.wait.success?
puts "Error mounting the filesystem".colorize(:red)
return
end
end
end
end
end