forked from glenux/mfm
feat: add support for more filesystems
This commit is contained in:
parent
cef669e15e
commit
64528611dd
5 changed files with 61 additions and 4 deletions
15
src/cli.cr
15
src/cli.cr
|
@ -69,8 +69,19 @@ module GX
|
|||
|
||||
names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String)
|
||||
@config.filesystems.each do |filesystem|
|
||||
result_name = filesystem.mounted? ? "#{filesystem.name} [open]" : filesystem.name
|
||||
ansi_name = filesystem.mounted? ? "#{filesystem.name} [#{ "open".colorize(:green) }]" : filesystem.name
|
||||
fs_str = filesystem.type.ljust(12,' ')
|
||||
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] = {
|
||||
filesystem: filesystem,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
|
||||
require "./filesystems/gocryptfs"
|
||||
require "./filesystems/sshfs"
|
||||
require "./filesystems/httpdirfs"
|
||||
require "./filesystems/filesystem"
|
||||
|
|
|
@ -8,7 +8,8 @@ module GX
|
|||
|
||||
use_yaml_discriminator "type", {
|
||||
gocryptfs: GoCryptFS,
|
||||
sshfs: SshFS
|
||||
sshfs: SshFS,
|
||||
httpdirfs: HttpDirFS
|
||||
}
|
||||
|
||||
property type : String
|
||||
|
|
|
@ -13,7 +13,7 @@ module GX
|
|||
|
||||
def after_initialize()
|
||||
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
|
||||
|
||||
def mounted? : Bool
|
||||
|
|
43
src/filesystems/httpdirfs.cr
Normal file
43
src/filesystems/httpdirfs.cr
Normal 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
|
||||
|
Loading…
Reference in a new issue