Class: FuseFS::DirLink

Inherits:
FuseDir show all
Defined in:
lib/fusefs/dirlink.rb

Overview

A FuseFS over an existing directory

Constant Summary

Constants inherited from FuseDir

FuseDir::INIT_TIMES

Instance Method Summary collapse

Methods inherited from FuseDir

#can_delete?, #can_mkdir?, #can_rmdir?, #can_write?, #delete, #executable?, #mkdir, #mounted, #raw_close, #raw_open, #raw_read, #raw_sync, #raw_truncate, #raw_write, #rename, #rmdir, #scan_path, #sigint, #sigterm, #split_path, #statistics, #times, #touch, #unmounted, #write_to, #xattr

Constructor Details

#initialize(dir) ⇒ DirLink

Returns a new instance of DirLink.



6
7
8
9
# File 'lib/fusefs/dirlink.rb', line 6

def initialize(dir)
  File.directory?(dir) or raise ArgumentError, "DirLink.initialize expects a valid directory!"
  @base = dir
end

Instance Method Details

#contents(path) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fusefs/dirlink.rb', line 23

def contents(path)
  fn = File.join(@base,path)
  Dir.entries(fn).map { |file|
  file = file.sub(/^#{fn}\/?/,'')
  if ['..','.'].include?(file)
    nil
  else
    file
  end
  }.compact.sort
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/fusefs/dirlink.rb', line 11

def directory?(path)
  File.directory?(File.join(@base,path))
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/fusefs/dirlink.rb', line 15

def file?(path)
  File.file?(File.join(@base,path))
end

#read_file(path) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/fusefs/dirlink.rb', line 35

def read_file(path)
  fn = File.join(@base,path)
  if File.file?(fn)
    IO.read(fn)
  else
    'No such file'
  end
end

#size(path) ⇒ Object



19
20
21
# File 'lib/fusefs/dirlink.rb', line 19

def size(path)
  File.size(File.join(@base,path))
end