file-find 0.4.4 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d99bb72ba56fc51995a186e6f06869318c1f29b1965d49d8aa42853aa341bf57
4
- data.tar.gz: c04db8e76c5a4ab4f953a373a6d089379cf4f99064ec18883a70ed7db1d82963
3
+ metadata.gz: f1b89ade1ff89a891f6aa2a44fa801fa9d2758b3784074f8868a5b3319dc68a5
4
+ data.tar.gz: 52f17946eb45f73bd98b0804a9696e5e4d7c2f17d9ea002a20fa109fde7e10f3
5
5
  SHA512:
6
- metadata.gz: bac0f7a26c507ae51dd15a19611bb0af91f43a93a717cf32a0c6787b244abb4680b8b12372525b51635696a4aa2c11f312107c1374c16f5f891c7d53cba111d8
7
- data.tar.gz: d27462d46d37ad567c9d7eaa29cadd7962e08066850d75a4b35983feb0a81a03ad63e224b10348099da0ffe74992b4604a576099dd1fde4f81f401d678d9baf5
6
+ metadata.gz: e6d0e1a56de403c2e7327f2d9af3ec6c68528d53f0cb0b83e40362b1ab8dddda020212cc726428ea0791130c098c1a41f53f22a65fad314d8dd9fee05fdc7fa3
7
+ data.tar.gz: 6c68a1b0e85905844b44feb04036834bb39e3ccaff5b732bb64d6280bb3eb86248f92f74570e60d37704fbc4d42ea4f99f2406c6d4be61ce7c9a8e3f89f1f1bb
checksums.yaml.gz.sig CHANGED
@@ -1,6 +1 @@
1
- h��߼�ɢ ϵ�g�Ï���o ($��� �>�u��J����D'���� ���nO�am ����>�)��z+������?ސ����^O��"Ѫ >v�d�O&��^�_9��/����:;µu
2
- xߎ\���Iv2�U��
3
- ~��ẖq���B9AH�麋EPu�i��w3��楚2�M��Ӆ�>k�(� ?��2�� �$y�j�Gu]�0J�z���#�,�'>�
4
- ��9���'�~�� RJE}�8{'�λ[�*ߗ
5
- b����۳w��X{�ţ;xE�%
6
- �9po�'���� k e~�Oi��Nۡ��@,����HsV�nJj�w��uD
1
+ ]����j��]i�<ǝ�ٲ�Ԕ�X�|sN��l�!ʋ��TT�%wtF�W�8�g�s]����Էâ�g�Z!1y`���|���."qe'V�?���$W�n���)��R Nf�ʍ��ޠ�2���qiN6_��Si^/q��A? �~��Θ����=$�O"���-���VB���$����|�����xc����פ6hWZnc��{�P���ܲ0��w����N]�/:ݧ%����:�ω�#��O��.�X�D2+��o`V��9�D؀.㫐�� �>d���p_2@t�6�ԧ���S·�=�ea1$-T��3|_��woP��BJ��g|�P�x�au��l���a�T�3��5�x.��5��_�
@@ -1,25 +1,44 @@
1
- == 0.4.3 - 8-Jun-2020
1
+ ## 0.5.1 - 17-Jun-2025
2
+ * Updated, fixed or skipped some specs on Windows.
3
+ * Some rubocop cleanup and minor refactors.
4
+ * Added a github workflow matrix to the repo.
5
+ * Added a rubocop config to the repo.
6
+ * Minor tweaks to the Rakefile.
7
+ * Added more information to the README.
8
+
9
+ ## 0.5.0 - 19-Jan-2021
10
+ * Switched from test-unit to rspec, with an added development
11
+ dependency on the fakefs gem.
12
+ * Switched from rdoc to markdown because github doesn't render rdoc
13
+ properly any more.
14
+ * Fixed a bug in the maxdepth option with root paths.
15
+ * Added a Gemfile.
16
+
17
+ ## 0.4.4 - 6-Aug-2020
18
+ * Added .rdoc extensions to the CHANGES, README and MANIFEST files.
19
+
20
+ ## 0.4.3 - 8-Jun-2020
2
21
  * Fixed a bug with ELOOP handling. Thanks go to joast for the spot and fix.
3
22
 
4
- == 0.4.2 - 6-May-2020
23
+ ## 0.4.2 - 6-May-2020
5
24
  * Added LICENSE file as required by the Apache-2.0 license.
6
25
 
7
- == 0.4.1 - 23-Jan-2019
26
+ ## 0.4.1 - 23-Jan-2019
8
27
  * Added metadata to the gemspec.
9
28
 
10
- == 0.4.0 - 26-Dec-2018
29
+ ## 0.4.0 - 26-Dec-2018
11
30
  * License changed to Apache-2.0.
12
31
  * Fixed a bug where mindepth and maxdepth would break if more than one
13
32
  path was specified as part of the rule. Thanks go to flagos for the spot.
14
33
  * The VERSION constant is now frozen.
15
34
  * The cert has been updated.
16
35
 
17
- == 0.3.9 - 16-Dec-2015
36
+ ## 0.3.9 - 16-Dec-2015
18
37
  * This gem is now signed.
19
38
  * Added a file-find.rb file for convenience.
20
39
  * Updates to the Rakefile and gemspec.
21
40
 
22
- == 0.3.8 - 12-Feb-2014
41
+ ## 0.3.8 - 12-Feb-2014
23
42
  * Removed all references to the Etc module since the sys-admin library now uses
24
43
  FFI and works with JRuby.
25
44
  * The :user, :group, and :inum options will now work on MS Windows if you have
@@ -29,27 +48,27 @@
29
48
  * Some tests that were previously omitted on Windows are now included.
30
49
  * Updates to the test suite, readme, etc.
31
50
 
32
- == 0.3.7 - 15-Jan-2014
51
+ ## 0.3.7 - 15-Jan-2014
33
52
  * Fixed a bug with brackets in the path name. Thanks go to Jeremy Lawler
34
53
  for the spot and the patch.
35
54
 
36
- == 0.3.6 - 6-Sep-2013
55
+ ## 0.3.6 - 6-Sep-2013
37
56
  * Removed rbconfig from library and test file. Just use File::ALT_SEPARATOR
38
57
  to check for Windows instead.
39
58
  * Removed unused variables.
40
59
  * Updated dev dependencies.
41
60
 
42
- == 0.3.5 - 15-Jul-2011
61
+ ## 0.3.5 - 15-Jul-2011
43
62
  * Fixed a bug with the :follow option.
44
63
  * Gemspec, Rakefile and test cleanup.
45
64
 
46
- == 0.3.4 - 19-Sep-2009
65
+ ## 0.3.4 - 19-Sep-2009
47
66
  * Fixed a packaging bug. Thanks go to Gabriel Horner for the spot.
48
67
  * Added the 'gem' task to the Rakefile for building the gem. Removed the
49
68
  gem builder code that was in the gemspec itself.
50
69
  * Updated the dependency for sys-admin to 1.5.2.
51
70
 
52
- == 0.3.3 - 3-Aug-2009
71
+ ## 0.3.3 - 3-Aug-2009
53
72
  * Now compatible with Ruby 1.9.x.
54
73
  * Added support for the :links option
55
74
  * Updated the :mount accessor to work properly if the value is changed
@@ -58,35 +77,35 @@
58
77
  * Added a fuller description to the gemspec.
59
78
  * Minor test refactoring.
60
79
 
61
- == 0.3.2 - 20-Feb-2009
80
+ ## 0.3.2 - 20-Feb-2009
62
81
  * Added support for the :mount option.
63
82
  * Added some basic tests for the :mount option.
64
83
 
65
- == 0.3.1 - 9-Jan-2009
84
+ ## 0.3.1 - 9-Jan-2009
66
85
  * Now defaults to using Etc instead of Sys::Admin for implementations
67
86
  that don't support building C extensions, e.g. JRuby.
68
87
  * Updated the test suite to work with JRuby.
69
88
  * Minor optimizations for symbolic perms and atime/ctime/mtime checks.
70
89
  Thanks go in part to Ryan Davis' flay library.
71
90
 
72
- == 0.3.0 - 30-Dec-2008
91
+ ## 0.3.0 - 30-Dec-2008
73
92
  * Added support for FileTest operations. All options passed to the constructor
74
93
  that end with '?' are now validated and treated as FileTest operations.
75
94
 
76
- == 0.2.5 - 29-Dec-2008
95
+ ## 0.2.5 - 29-Dec-2008
77
96
  * Added maxdepth and mindepth support.
78
97
  * Added a 'clean' rake task to cleanup any test-unit results files.
79
98
 
80
- == 0.2.4 - 10-Dec-2008
99
+ ## 0.2.4 - 10-Dec-2008
81
100
  * Added support for symbolic permissions. Thanks go to Bill Kleb for the
82
101
  suggestion and to Hal Fulton for providing the solution.
83
102
 
84
- == 0.2.3 - 25-Nov-2008
103
+ ## 0.2.3 - 25-Nov-2008
85
104
  * Added mtime support. My previous concerns, which I believe stemmed from
86
105
  the find(2) man page on Solaris 10 with regards to atime checks modifying
87
106
  the mtime, appear have been unfounded.
88
107
 
89
- == 0.2.2 - 19-Nov-2008
108
+ ## 0.2.2 - 19-Nov-2008
90
109
  * The :user and :group options now accept a name or a numeric id. Thanks go
91
110
  to Bill Kleb for the suggestion.
92
111
  * Fixed yet another path bug for MS Windows.
@@ -95,23 +114,23 @@
95
114
  * Added sys-admin and test-unit as prerequisites.
96
115
  * Added tests for the :user and :group options.
97
116
 
98
- == 0.2.1 - 4-Oct-2007
117
+ ## 0.2.1 - 4-Oct-2007
99
118
  * Added the File::Find#previous method, which lets you see the previous
100
119
  match, if any.
101
120
  * Path name bug fix for MS Windows.
102
121
  * Test suite bug fixes for MS Windows (perm test now skipped).
103
122
  * Inaccessible directories are now skipped instead of raising an error.
104
123
 
105
- == 0.2.0 - 26-Apr-2007
124
+ ## 0.2.0 - 26-Apr-2007
106
125
  * Fixed a bug where it was not traversing subdirectories.
107
126
  * Added support for the perm and prune options.
108
127
 
109
- == 0.1.1 - 25-Apr-2007
128
+ ## 0.1.1 - 25-Apr-2007
110
129
  * The default for name is now '*', i.e. everything.
111
130
  * Fixed a bug where directories were not matched. Thanks go to Leslie Viljoen
112
131
  for the spot.
113
132
  * The size option now accepts strings with comparable operators. For example,
114
133
  you can now look for files greater than 400 bytes with the string "> 400".
115
134
 
116
- == 0.1.0 - 24-Apr-2007
135
+ ## 0.1.0 - 24-Apr-2007
117
136
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -1,6 +1,7 @@
1
- * CHANGES
2
- * LICENSE
3
- * MANIFEST
1
+ * CHANGES.md
2
+ * Gemfile
3
+ * LICENSE.md
4
+ * MANIFEST.md
4
5
  * Rakefile
5
6
  * README
6
7
  * file-find.gemspec
@@ -1,15 +1,25 @@
1
- = Description
1
+ [![Ruby](https://github.com/djberg96/file-find/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/file-find/actions/workflows/ruby.yml)
2
+
3
+ ## Description
2
4
 
3
5
  This is a drop-in replacement for the find module currently in the standard
4
6
  library. It is modeled on a typical 'find' command found on most Unix systems.
5
7
 
6
- = Installation
8
+ ## Installation
9
+
10
+ `gem install file-find`
7
11
 
8
- gem install file-find
12
+ ## Specs
9
13
 
10
- = Synopsis
14
+ Although this gem will work with Ruby 2.x or 3.x, you will need Ruby 3.x to
15
+ run the specs locally because of development dependencies.
11
16
 
12
- require 'file/find'
17
+ ## Adding the trusted cert
18
+ `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/file-find/main/certs/djberg96_pub.pem)`
19
+
20
+ ## Synopsis
21
+ ```ruby
22
+ require 'file/find' # 'file-find' also works
13
23
 
14
24
  rule = File::Find.new(
15
25
  :pattern => "*.rb",
@@ -20,15 +30,16 @@ gem install file-find
20
30
  rule.find{ |f|
21
31
  puts f
22
32
  }
33
+ ```
23
34
 
24
- = Rationale
35
+ ## Rationale
25
36
 
26
37
  The current find module in the standard library is inadequate. It is, quite
27
38
  frankly, not much more than a plain Dir.glob call. This library provides an
28
39
  interface based on options typically available on your command line 'find'
29
40
  command, thus allowing you much greater control over how you find your files.
30
41
 
31
- = Options
42
+ ## Options
32
43
 
33
44
  * atime
34
45
  * ctime
@@ -47,18 +58,18 @@ command, thus allowing you much greater control over how you find your files.
47
58
  * size
48
59
  * user (name or id)
49
60
 
50
- In addition to the above options, FileTest methods such as 'readable?' and
51
- 'writable?' may be used as keys, with true or false for their values.
61
+ In addition to the above options, `FileTest` methods such as `readable?` and
62
+ `writable?` may be used as keys, with true or false for their values.
52
63
 
53
- See the RDoc documentation for more details about these options.
64
+ See the documentation for more details about these options.
54
65
 
55
- = Future Plans
66
+ ## Future Plans
56
67
 
57
68
  None at this time. Please log any feature requests on the project page at:
58
69
 
59
70
  http://github.com/djberg96/file-find
60
71
 
61
- = Options I won't support
72
+ ## Options I won't support
62
73
 
63
74
  Generally speaking, anything that would require mucking around with C code
64
75
  or is just too difficult to implement in a cross platform manner will not be
@@ -74,35 +85,38 @@ supported. These include the following options:
74
85
 
75
86
  * ok - This is not interactive software.
76
87
 
77
- = Known Issues
88
+ ## Known Issues
89
+
90
+ The `:perm` option is limited to 0644 and 0444 on MS Windows.
78
91
 
79
- The :perm option is limited to 0644 and 0444 on MS Windows.
92
+ The `:user`, `:group`, and `:inum` options require the win32-file gem to work
93
+ properly on MS Windows. However, win32-file is not officially a dependency.
80
94
 
81
- The :user, :group, and :inum options require the win32-file gem to work
82
- properly on MS Windows. However, it is not officially a dependency.
95
+ Some specs on Windows are marked pending for now because there's some issue
96
+ interacting with the FakeFS gem on Windows.
83
97
 
84
- = Bugs
98
+ ## Bugs
85
99
 
86
100
  None that I'm aware of beyond the ones mentioned in the Known Issues. Please
87
101
  log any bug reports on the project page at:
88
102
 
89
103
  http://github.com/djberg96/file-find
90
104
 
91
- = Acknowledgements
105
+ ## Acknowledgements
92
106
 
93
107
  * Richard Clamp's File::Find::Rule Perl module for additional ideas and
94
108
  inspiration.
95
109
  * Bill Kleb for ideas regarding name, group and perm enhancements.
96
110
  * Hal Fulton for his implementation of symbolic permissions.
97
111
 
98
- = License
112
+ ## License
99
113
 
100
114
  Apache-2.0
101
115
 
102
- = Copyright
116
+ ## Copyright
103
117
 
104
- (C) 2007-2020, Daniel J. Berger, All Rights Reserved
118
+ (C) 2007-2025, Daniel J. Berger, All Rights Reserved
105
119
 
106
- = Author
120
+ ## Author
107
121
 
108
122
  Daniel J. Berger
data/Rakefile CHANGED
@@ -1,16 +1,17 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
4
5
 
5
- CLEAN.include("**/*.gem", "**/*.rbc", "**/link*")
6
+ CLEAN.include("**/*.gem", "**/*.rbc", "**/link*", "*.lock")
6
7
 
7
8
  namespace :gem do
8
9
  desc 'Create the file-find gem'
9
10
  task :create => [:clean] do
10
11
  require 'rubygems/package'
11
- spec = eval(IO.read('file-find.gemspec'))
12
+ spec = Gem::Specification.load('file-find.gemspec')
12
13
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
- Gem::Package.build(spec, true)
14
+ Gem::Package.build(spec)
14
15
  end
15
16
 
16
17
  desc "Install the file-find gem"
@@ -21,10 +22,15 @@ namespace :gem do
21
22
  end
22
23
  end
23
24
 
24
- Rake::TestTask.new do |t|
25
- task :test => 'clean'
26
- t.warning = true
27
- t.verbose = true
25
+ RuboCop::RakeTask.new
26
+
27
+ RSpec::Core::RakeTask.new(:spec) do |t|
28
+ t.pattern = ['spec/file_find_spec.rb']
29
+ end
30
+
31
+ # Clean up afterwards
32
+ Rake::Task[:spec].enhance do
33
+ Rake::Task[:clean].invoke
28
34
  end
29
35
 
30
- task :default => :test
36
+ task :default => :spec
data/file-find.gemspec CHANGED
@@ -2,30 +2,34 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-find'
5
- spec.version = '0.4.4'
5
+ spec.version = '0.5.1'
6
6
  spec.author = 'Daniel Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.summary = 'A better way to find files'
9
9
  spec.email = 'djberg96@gmail.com'
10
10
  spec.homepage = 'http://github.com/djberg96/file-find'
11
- spec.test_file = 'test/test_file_find.rb'
11
+ spec.test_file = 'spec/file_find_spec.rb'
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
- spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc', 'MANIFEST.rdoc']
16
-
17
15
  spec.metadata = {
18
- 'homepage_uri' => 'https://github.com/djberg96/file-find',
19
- 'bug_tracker_uri' => 'https://github.com/djberg96/file-find/issues',
20
- 'changelog_uri' => 'https://github.com/djberg96/file-find/blob/master/CHANGES',
21
- 'documentation_uri' => 'https://github.com/djberg96/file-find/wiki',
22
- 'source_code_uri' => 'https://github.com/djberg96/file-find',
23
- 'wiki_uri' => 'https://github.com/djberg96/file-find/wiki'
16
+ 'homepage_uri' => 'https://github.com/djberg96/file-find',
17
+ 'bug_tracker_uri' => 'https://github.com/djberg96/file-find/issues',
18
+ 'changelog_uri' => 'https://github.com/djberg96/file-find/blob/main/CHANGES.md',
19
+ 'documentation_uri' => 'https://github.com/djberg96/file-find/wiki',
20
+ 'source_code_uri' => 'https://github.com/djberg96/file-find',
21
+ 'wiki_uri' => 'https://github.com/djberg96/file-find/wiki',
22
+ 'rubygems_mfa_required' => 'true',
23
+ 'github_repo' => 'https://github.com/djberg96/file-find',
24
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
24
25
  }
25
26
 
26
- spec.add_dependency('sys-admin', '>= 1.6.0')
27
- spec.add_development_dependency('test-unit')
27
+ spec.add_dependency('sys-admin', '~> 1.7')
28
+ spec.add_development_dependency('rspec', '~> 3.9')
29
+ spec.add_development_dependency('fakefs', '~> 3.0')
28
30
  spec.add_development_dependency('rake')
31
+ spec.add_development_dependency('rubocop')
32
+ spec.add_development_dependency('rubocop-rspec')
29
33
 
30
34
  spec.description = <<-EOF
31
35
  The file-find library provides a better, more object oriented approach
data/lib/file/find.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'sys/admin'
3
5
 
@@ -7,9 +9,11 @@ rescue LoadError
7
9
  # Do nothing, not required, just nicer.
8
10
  end
9
11
 
12
+ # The File::Find class encapsulates 'rules' that you create and use to find
13
+ # files on your filesystem.
10
14
  class File::Find
11
15
  # The version of the file-find library
12
- VERSION = '0.4.4'.freeze
16
+ VERSION = '0.5.1'
13
17
 
14
18
  # :stopdoc:
15
19
  VALID_OPTIONS = %w[
@@ -31,7 +35,7 @@ class File::Find
31
35
  prune
32
36
  size
33
37
  user
34
- ]
38
+ ].freeze
35
39
  # :startdoc:
36
40
 
37
41
  # The starting path(s) for the search. The default is the current directory.
@@ -209,6 +213,7 @@ class File::Find
209
213
  def find
210
214
  results = [] unless block_given?
211
215
  paths = @path.is_a?(String) ? [@path] : @path # Ruby 1.9.x compatibility
216
+ queue = paths.dup
212
217
 
213
218
  if @prune
214
219
  prune_regex = Regexp.new(@prune)
@@ -216,14 +221,16 @@ class File::Find
216
221
  prune_regex = nil
217
222
  end
218
223
 
219
- paths.each{ |path|
224
+ # rubocop:disable Metrics/BlockLength
225
+ until queue.empty?
226
+ path = queue.shift
220
227
  begin
221
- Dir.foreach(path){ |file|
228
+ Dir.foreach(path) do |file|
222
229
  next if file == '.'
223
230
  next if file == '..'
224
231
 
225
- if prune_regex
226
- next if prune_regex.match(file)
232
+ if prune_regex && prune_regex.match(file)
233
+ next
227
234
  end
228
235
 
229
236
  file = File.join(path, file)
@@ -241,8 +248,9 @@ class File::Find
241
248
  end
242
249
  end
243
250
 
244
- # We need to escape any brackets in the directory name.
245
- glob = File.join(File.dirname(file).gsub(/([\[\]])/,'\\\\\1'), @name)
251
+ # We need to escape any brackets in the directory name, unless already escaped.
252
+ temp = File.dirname(file).gsub(/(?<!\\)([\[\]])/, '\\\\\1')
253
+ glob = File.join(temp, @name)
246
254
 
247
255
  # Dir[] doesn't like backslashes
248
256
  if File::ALT_SEPARATOR
@@ -250,38 +258,32 @@ class File::Find
250
258
  glob.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
251
259
  end
252
260
 
253
- if @mount
254
- next unless stat_info.dev == @filesystem
261
+ if @mount && stat_info.dev != @filesystem
262
+ next
255
263
  end
256
264
 
257
- if @links
258
- next unless stat_info.nlink == @links
265
+ if @links && stat_info.nlink != @links
266
+ next
259
267
  end
260
268
 
261
269
  if @maxdepth || @mindepth
262
- file_depth = file.split(File::SEPARATOR).length
270
+ file_depth = file.split(File::SEPARATOR).reject(&:empty?).length
263
271
  current_base_path = [@path].flatten.find{ |tpath| file.include?(tpath) }
264
272
  path_depth = current_base_path.split(File::SEPARATOR).length
265
273
 
266
274
  depth = file_depth - path_depth
267
275
 
268
276
  if @maxdepth && (depth > @maxdepth)
269
- if File.directory?(file)
270
- unless paths.include?(file) && depth > @maxdepth
271
- paths << file
272
- end
277
+ if File.directory?(file) && !(paths.include?(file) && depth > @maxdepth)
278
+ queue << file
273
279
  end
274
-
275
280
  next
276
281
  end
277
282
 
278
283
  if @mindepth && (depth < @mindepth)
279
- if File.directory?(file)
280
- unless paths.include?(file) && depth < @mindepth
281
- paths << file
282
- end
284
+ if File.directory?(file) && !(paths.include?(file) && depth < @mindepth)
285
+ queue << file
283
286
  end
284
-
285
287
  next
286
288
  end
287
289
  end
@@ -289,8 +291,8 @@ class File::Find
289
291
  # Add directories back onto the list of paths to search unless
290
292
  # they've already been added
291
293
  #
292
- if stat_info.directory?
293
- paths << file unless paths.include?(file)
294
+ if stat_info.directory? && !paths.include?(file)
295
+ queue << file
294
296
  end
295
297
 
296
298
  next unless Dir[glob].include?(file)
@@ -298,7 +300,7 @@ class File::Find
298
300
  unless @filetest.empty?
299
301
  file_test = true
300
302
 
301
- @filetest.each{ |array|
303
+ @filetest.each do |array|
302
304
  meth = array[0]
303
305
  bool = array[1]
304
306
 
@@ -306,7 +308,7 @@ class File::Find
306
308
  file_test = false
307
309
  break
308
310
  end
309
- }
311
+ end
310
312
 
311
313
  next unless file_test
312
314
  end
@@ -330,8 +332,8 @@ class File::Find
330
332
  end
331
333
  end
332
334
 
333
- if @ftype
334
- next unless File.ftype(file) == @ftype
335
+ if @ftype && File.ftype(file) != @ftype
336
+ next
335
337
  end
336
338
 
337
339
  if @group
@@ -354,8 +356,8 @@ class File::Find
354
356
  end
355
357
  end
356
358
 
357
- if @inum
358
- next unless stat_info.ino == @inum
359
+ if @inum && stat_info.ino != @inum
360
+ next
359
361
  end
360
362
 
361
363
  # Note that only 0644 and 0444 are supported on MS Windows.
@@ -364,7 +366,7 @@ class File::Find
364
366
  octal_perm = sym2oct(@perm)
365
367
  next unless stat_info.mode & octal_perm == octal_perm
366
368
  else
367
- next unless sprintf("%o", stat_info.mode & 07777) == sprintf("%o", @perm)
369
+ next unless format('%o', stat_info.mode & 07777) == format('%o', @perm)
368
370
  end
369
371
  end
370
372
 
@@ -414,11 +416,12 @@ class File::Find
414
416
  end
415
417
 
416
418
  @previous = file unless @previous == file
417
- }
419
+ end
418
420
  rescue Errno::EACCES
419
421
  next # Skip inaccessible directories
420
422
  end
421
- }
423
+ end
424
+ # rubocop:enable Metrics/BlockLength
422
425
 
423
426
  block_given? ? nil : results
424
427
  end
@@ -475,17 +478,17 @@ class File::Find
475
478
  match = cmd.match(regex)
476
479
  raise "Invalid symbolic permissions: '#{str}'" if match.nil?
477
480
 
478
- who, what, how = match.to_a[1..-1]
481
+ who, what, how = match.to_a[1..]
479
482
 
480
- who = who.split(//).inject(0){ |num,b| num |= left[b]; num }
481
- how = how.split(//).inject(0){ |num,b| num |= right[b]; num }
483
+ who = who.chars.inject(0){ |num, b| num | left[b] }
484
+ how = how.chars.inject(0){ |num, b| num | right[b] }
482
485
  mask = who & how
483
486
 
484
487
  case what
485
488
  when '+'
486
- perm = perm | mask
489
+ perm |= mask
487
490
  when '-'
488
- perm = perm & ~mask
491
+ perm &= ~mask
489
492
  when '='
490
493
  perm = mask
491
494
  end
data/lib/file-find.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'file/find'