50 lines
1.1 KiB
Crystal
50 lines
1.1 KiB
Crystal
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
#
|
|
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
|
|
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
|
|
|
|
require "shellwords"
|
|
require "./abstract_filesystem"
|
|
|
|
module GX
|
|
module Filesystem
|
|
class HttpDirFS < AbstractFilesystem
|
|
getter name : String = ""
|
|
getter url : String = ""
|
|
|
|
@[YAML::Field(key: "mount_dir", ignore: true)]
|
|
getter mount_dir : String = ""
|
|
|
|
include FilesystemBase
|
|
|
|
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
|
|
end
|
|
|