Class: FakeFtp::ServerCommands::Dele

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_ftp/server_commands/dele.rb

Instance Method Summary collapse

Instance Method Details

#run(ctx, filename = '') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fake_ftp/server_commands/dele.rb', line 6

def run(ctx, filename = '', *)
  files_to_delete = ctx.store.values.select do |f|
    if ctx.absolute?
      ctx.abspath(::File.basename(filename)) == ctx.abspath(f.name)
    else
      ::File.basename(filename) == f.name
    end
  end

  return '550 Delete operation failed.' if files_to_delete.empty?

  ctx.store.reject! do |_, f|
    files_to_delete.include?(f)
  end

  '250 Delete operation successful.'
end