Skip to content

[IMPROVEMENT] Cmd Size and exotic filesystem #39

@anykeyh

Description

@anykeyh

The command SIZE is calling read method of the file driver. Which is bad in the case your driver is not a file system.

For example, I ftpd with google bucket and it works perfectly except for this command.

For informations, we monkey-patched the method internally for our tool, like that:

( PS: I'm not gonna open a pull request as it's not just debugging feature, and better idea of implementation would exists )

# frozen_string_literal: true

require_relative 'command_handler'

module Ftpd

  class CmdSize < CommandHandler

    def cmd_size(path)
      ensure_logged_in
      ensure_file_system_supports :read
      syntax_error unless path
      path = File.expand_path(path, name_prefix)
      ensure_accessible(path)
      ensure_exists(path)
      if file_system.respond_to?(:size)
        size = file_system.size(path, data_type).to_i
        reply "213 #{size}"
      else
        file_system.read(path) do |file|
          if data_type == 'A'
            output = StringIO.new
            io = Ftpd::Stream.new(output, data_type)
            io.write(file)
            size = output.size
          else
            size = file.size
          end
          reply "213 #{size}"
        end

      end

    end

  end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions