diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 381a35e..23714e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - ruby: [ 'head', '3.0', '2.7', '2.6', '2.5' ] + ruby: [ 'head', '3.0', '2.7', '2.6', '2.5', '2.4', '2.3' ] os: [ 'ubuntu-latest', 'windows-latest' ] include: - { os: macos-latest, ruby: '2.6' } diff --git a/fileutils.gemspec b/fileutils.gemspec index 76baea3..53c32e7 100644 --- a/fileutils.gemspec +++ b/fileutils.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.require_path = %w{lib} s.files = ["LICENSE.txt", "README.md", "Rakefile", "fileutils.gemspec", "lib/fileutils.rb"] - s.required_ruby_version = ">= 2.5.0" + s.required_ruby_version = ">= 2.3.0" s.authors = ["Minero Aoki"] s.email = [nil] diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 69de458..a2ad0c0 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -837,8 +837,13 @@ def compare_file(a, b) def compare_stream(a, b) bsize = fu_stream_blksize(a, b) - sa = String.new(capacity: bsize) - sb = String.new(capacity: bsize) + if RUBY_VERSION > "2.4" + sa = String.new(capacity: bsize) + sb = String.new(capacity: bsize) + else + sa = String.new + sb = String.new + end begin a.read(bsize, sa) @@ -1287,7 +1292,12 @@ def entries opts = {} opts[:encoding] = fu_windows? ? ::Encoding::UTF_8 : path.encoding - files = Dir.children(path, **opts) + files = if Dir.respond_to?(:children) + Dir.children(path, **opts) + else + Dir.entries(path(), **opts) + .reject {|n| n == '.' or n == '..' } + end untaint = RUBY_VERSION < '2.7' files.map {|n| Entry_.new(prefix(), join(rel(), untaint ? n.untaint : n)) }