Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address net-ftp warnings #106

Merged
merged 2 commits into from May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
## mini_portile changelog

### 2.5.3 / unreleased

Make `net-ftp` an optional dependency, since requiring it as a hard dependency in v2.5.2 caused warnings to be emitted by Ruby 2.7 and earlier. A warning message is emitted if FTP functionality is called and `net-ftp` isn't available; this should only happen in Ruby 3.1 and later.


### 2.5.2 / 2021-05-28

#### Dependencies
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
@@ -1,4 +1,6 @@
source 'https://rubygems.org'

gem "net-ftp" if Gem::Requirement.new("> 3.1.0.dev").satisfied_by?(Gem::Version.new(RUBY_VERSION))

# Specify your gem's dependencies in mini_portile2.gemspec
gemspec
8 changes: 3 additions & 5 deletions lib/mini_portile2/mini_portile.rb
@@ -1,7 +1,6 @@
require 'rbconfig'
require 'net/http'
require 'net/https'
require 'net/ftp'
require 'fileutils'
require 'tempfile'
require 'digest'
Expand Down Expand Up @@ -473,7 +472,6 @@ def download_file(url, full_path, count = 3)
def download_file_http(url, full_path, count = 3)
filename = File.basename(full_path)
with_tempfile(filename, full_path) do |temp_file|
progress = 0
total = 0
params = {
"Accept-Encoding" => 'identity',
Expand All @@ -482,7 +480,6 @@ def download_file_http(url, full_path, count = 3)
if total
new_progress = (bytes * 100) / total
message "\rDownloading %s (%3d%%) " % [filename, new_progress]
progress = new_progress
else
# Content-Length is unavailable because Transfer-Encoding is chunked
message "\rDownloading %s " % [filename]
Expand Down Expand Up @@ -530,16 +527,15 @@ def download_file_file(uri, full_path)
end

def download_file_ftp(uri, full_path)
require "net/ftp"
filename = File.basename(uri.path)
with_tempfile(filename, full_path) do |temp_file|
progress = 0
total = 0
params = {
:content_length_proc => lambda{|length| total = length },
:progress_proc => lambda{|bytes|
new_progress = (bytes * 100) / total
message "\rDownloading %s (%3d%%) " % [filename, new_progress]
progress = new_progress
}
}
if ENV["ftp_proxy"]
Expand All @@ -555,6 +551,8 @@ def download_file_ftp(uri, full_path)
end
output
end
rescue LoadError
raise LoadError, "Ruby #{RUBY_VERSION} does not provide the net-ftp gem, please add it as a dependency if you need to use FTP"
rescue Net::FTPError
return false
end
Expand Down
2 changes: 0 additions & 2 deletions mini_portile2.gemspec
Expand Up @@ -33,8 +33,6 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.3.0"

spec.add_dependency "net-ftp", "~> 0.1"

spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "minitar", "~> 0.7"
spec.add_development_dependency "minitest", "~> 5.11"
Expand Down
10 changes: 6 additions & 4 deletions test/test_download.rb
Expand Up @@ -18,10 +18,12 @@ def server_must_receive_connection(connections = 3, &block)
end
end

block.call

thread.kill
server.close
begin
block.call
ensure
thread.kill
server.close
end

request_count.must_be :>, 0
end
Expand Down