Class: FTPMVC::Ftpd::FileSystem

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/ftpmvc/ftpd/file_system.rb

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(application) ⇒ FileSystem

Returns a new instance of FileSystem.



10
11
12
# File 'lib/ftpmvc/ftpd/file_system.rb', line 10

def initialize(application)
  @application = application
end

Instance Method Details

#accessible?(path) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/ftpmvc/ftpd/file_system.rb', line 34

def accessible?(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#accessible?(#{path})" }
  true
end

#dir(path) ⇒ Object



14
15
16
17
# File 'lib/ftpmvc/ftpd/file_system.rb', line 14

def dir(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#dir(#{path})" }
  @application.index(path.gsub('/*', '')).map { |node| ::File.join(path, node.name) }
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/ftpmvc/ftpd/file_system.rb', line 19

def directory?(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#directory?(#{path})" }
  @application.directory?(path.gsub('/*', ''))
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/ftpmvc/ftpd/file_system.rb', line 39

def exists?(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#exists?(#{path})" }
  @application.exists?(path)
end

#file_info(path) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ftpmvc/ftpd/file_system.rb', line 44

def file_info(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#file_info(#{path})" }
  ::Ftpd::FileInfo.new(
    :ftype => directory?(path) ? 'directory' : 'file',
    :group => 'nogroup',
    :mode => directory?(path) ? 0750 : 0640,
    :mtime => Time.now,
    :nlink => 33,
    :owner => 'nobody',
    :path => path,
    :size => 0)
end

#read(path) {|@application.get(path)| ... } ⇒ Object

Yields:

  • (@application.get(path))


24
25
26
27
# File 'lib/ftpmvc/ftpd/file_system.rb', line 24

def read(path)
  logger.debug { "FTPMVC::Ftpd::FileSystem#read(#{path})" }
  yield @application.get(path)
end

#write(path, stream) ⇒ Object



29
30
31
32
# File 'lib/ftpmvc/ftpd/file_system.rb', line 29

def write(path, stream)
  logger.debug { "FTPMVC::Ftpd::FileSystem#write(#{path}, ...)" }
  @application.put(path, Input.new(stream))
end