Module: RFuse
- Defined in:
- lib/rfuse.rb,
lib/rfuse/stat.rb,
lib/rfuse/flock.rb,
lib/rfuse/rfuse.rb,
lib/rfuse/statvfs.rb,
lib/rfuse/version.rb,
lib/rfuse/gem_version.rb
Overview
Ruby FUSE (Filesystem in USErspace) binding
Defined Under Namespace
Modules: Adapter Classes: Error, Filler, Flock, Fuse, FuseDelegator, Stat, StatVfs
Constant Summary collapse
- VERSION =
"2.0.0"
Class Method Summary collapse
-
.main(argv = ARGV.dup, extra_options = [], extra_options_usage = nil, device = nil, exec = File.basename($PROGRAM_NAME)) {|options, argv| ... } ⇒ Object
Convenience method to launch a fuse filesystem, with nice usage messages and default signal traps.
-
.parse_options(argv, *local_opts, desc: nil, exec: $0) ⇒ Hash<Symbol,String|Boolean>
Parse mount arguments and options.
-
.usage(device = nil, exec = File.basename($PROGRAM_NAME)) ⇒ String
Generate a usage string.
Class Method Details
.main(argv = ARGV.dup, extra_options = [], extra_options_usage = nil, device = nil, exec = File.basename($PROGRAM_NAME)) {|options, argv| ... } ⇒ Object
Convenience method to launch a fuse filesystem, with nice usage messages and default signal traps
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/rfuse.rb', line 199 def self.main(argv = ARGV.dup, = [], = nil, device = nil, exec = File.basename($PROGRAM_NAME)) begin fuse_help = ['Filesystem options:',,device,''].compact.join("\n") = (argv, *, desc: && fuse_help, exec: exec) unless [:mountpoint] warn "rfuse: failed, no mountpoint provided" puts usage(device,exec) return nil end fs = yield , argv raise Error, 'no filesystem provided' unless fs # create can pass the extra options to a constructor so order and existence is important. = .each_with_object({}) { |k,h| h[k] = .delete(k) } fuse = create(argv: argv, fs: fs, options: ) return nil if [:show_help] || [:show_version] raise Error, "filesystem #{fs} not mounted" unless fuse&.mounted? fuse.run(**) rescue Error => e # These errors are produced generally because the user passed bad arguments etc.. puts usage(device, exec) unless [:help] warn "rfuse failed: #{e.}" nil rescue StandardError => e # These are other errors related the yield block warn e. warn e.backtrace.join("\n") end end |
.parse_options(argv, *local_opts, desc: nil, exec: $0) ⇒ Hash<Symbol,String|Boolean>
Parse mount arguments and options
Fuse itself will normalise arguments
mount -t fuse </path/to/fs.rb>#<device> mountpoint [options...]
mount.fuse </path/to/fs.rb>#<device> mountpoint [options...]
both result in the following command execution
/path/to/fs.rb [device] mountpoint [-h] [-d] [-o [opt,optkey=value,...]]
which this method will parse into a Hash with the following special keys
:device
- the optional mount device, removed from argv if present:mountpoint
- required mountpoint:help
- if -h was supplied - will print help text (and not mount the filesystem!):debug
- if -d (or -o debug) was supplied - will print debug output from the underlying FUSE library
and any other supplied options.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rfuse.rb', line 81 def self.(argv, *local_opts, desc: nil, exec: $0) def desc.fuse_help self end if desc && !desc.empty? argv.unshift(exec) unless argv.size >= 2 && argv[0..1].none? { |a| a.start_with?('-') } run_args = FFI::Libfuse::Main.fuse_parse_cmdline(*argv, handler: desc) run_args[:help] = true if run_args[:show_help] # compatibility device_opts = { 'subtype=' => :device, 'fsname=' => :device } local_opt_conf = local_opts.each.with_object(device_opts) do |o, conf| conf.merge!({ "#{o}=" => o.to_sym, "#{o}" => o.to_sym }) end fuse_args = run_args.delete(:args) fuse_args.parse!(local_opt_conf, run_args, **{}) do |key:, value:, data:, **_| data[key] = value key == :device ? :keep : :discard end argv.replace(fuse_args.argv) # The first arg is actually the device and ignored in future calls to parse opts # (eg during fuse_new, but rfuse used to return the mountpoint here. argv[0] = run_args[:mountpoint] run_args end |
.usage(device = nil, exec = File.basename($PROGRAM_NAME)) ⇒ String
Generate a usage string
117 118 119 |
# File 'lib/rfuse.rb', line 117 def self.usage(device = nil, exec = File.basename($PROGRAM_NAME)) "Usage:\n #{exec} #{device} mountpoint [-h] [-d] [-o [opt,optkey=value,...]]\n" end |