Module: Ftpd::FileSystemHelper

Included in:
CommandHandler
Defined in:
lib/ftpd/file_system_helper.rb

Instance Method Summary collapse

Instance Method Details

#ensure_accessible(path) ⇒ Object



20
21
22
23
24
# File 'lib/ftpd/file_system_helper.rb', line 20

def ensure_accessible(path)
  unless file_system.accessible?(path)
    error 'Access denied', 550
  end
end

#ensure_directory(path) ⇒ Object



38
39
40
41
42
# File 'lib/ftpd/file_system_helper.rb', line 38

def ensure_directory(path)
  unless file_system.directory?(path)
    error 'Not a directory', 550
  end
end

#ensure_does_not_exist(path) ⇒ Object



32
33
34
35
36
# File 'lib/ftpd/file_system_helper.rb', line 32

def ensure_does_not_exist(path)
  if file_system.exists?(path)
    error 'Already exists', 550
  end
end

#ensure_exists(path) ⇒ Object



26
27
28
29
30
# File 'lib/ftpd/file_system_helper.rb', line 26

def ensure_exists(path)
  unless file_system.exists?(path)
    error 'No such file or directory', 550
  end
end

#ensure_file_system_supports(method) ⇒ Object



14
15
16
17
18
# File 'lib/ftpd/file_system_helper.rb', line 14

def ensure_file_system_supports(method)
  unless file_system.respond_to?(method)
    unimplemented_error
  end
end

#path_list(path) ⇒ Object



7
8
9
10
11
12
# File 'lib/ftpd/file_system_helper.rb', line 7

def path_list(path)
  if file_system.directory?(path)
    path = File.join(path, '*')
  end
  file_system.dir(path).sort
end

#unique_path(path) ⇒ Object



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

def unique_path(path)
  suffix = nil
  100.times do
    path_with_suffix = [path, suffix].compact.join('.')
    unless file_system.exists?(path_with_suffix)
      return path_with_suffix
    end
    suffix = generate_suffix
  end
  raise "Unable to find unique path"
end