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



22
23
24
25
26
# File 'lib/ftpd/file_system_helper.rb', line 22

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

#ensure_directory(path) ⇒ Object



40
41
42
43
44
# File 'lib/ftpd/file_system_helper.rb', line 40

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

#ensure_does_not_exist(path) ⇒ Object



34
35
36
37
38
# File 'lib/ftpd/file_system_helper.rb', line 34

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

#ensure_exists(path) ⇒ Object



28
29
30
31
32
# File 'lib/ftpd/file_system_helper.rb', line 28

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

#ensure_file_system_supports(method) ⇒ Object



16
17
18
19
20
# File 'lib/ftpd/file_system_helper.rb', line 16

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

#path_list(path) ⇒ Object



9
10
11
12
13
14
# File 'lib/ftpd/file_system_helper.rb', line 9

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

#unique_path(path) ⇒ Object



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

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