file-find 0.4.0 → 0.5.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +39 -19
- data/Gemfile +3 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +4 -2
- data/README.md +109 -0
- data/Rakefile +4 -6
- data/file-find.gemspec +13 -5
- data/lib/file/find.rb +9 -6
- data/spec/file_find_spec.rb +613 -0
- metadata +48 -30
- metadata.gz.sig +0 -0
- data/README +0 -96
- data/test/test_file_find.rb +0 -568
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-find
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Berger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- |
|
@@ -35,36 +35,50 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date:
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: sys-admin
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
46
|
+
version: '1.7'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
53
|
+
version: '1.7'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
|
-
name:
|
55
|
+
name: rspec
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '3.9'
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '3.9'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: fakefs
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.3'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.3'
|
68
82
|
- !ruby/object:Gem::Dependency
|
69
83
|
name: rake
|
70
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,29 +101,34 @@ description: |2
|
|
87
101
|
email: djberg96@gmail.com
|
88
102
|
executables: []
|
89
103
|
extensions: []
|
90
|
-
extra_rdoc_files:
|
91
|
-
- README
|
92
|
-
- CHANGES
|
93
|
-
- MANIFEST
|
104
|
+
extra_rdoc_files: []
|
94
105
|
files:
|
95
|
-
-
|
96
|
-
- test
|
97
|
-
- test/test_file_find.rb
|
98
|
-
- README
|
99
|
-
- Rakefile
|
100
|
-
- MANIFEST
|
106
|
+
- LICENSE
|
101
107
|
- file-find.gemspec
|
108
|
+
- spec
|
109
|
+
- spec/file_find_spec.rb
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- MANIFEST.md
|
113
|
+
- certs
|
114
|
+
- certs/djberg96_pub.pem
|
102
115
|
- lib
|
103
116
|
- lib/file-find.rb
|
104
117
|
- lib/file
|
105
118
|
- lib/file/find.rb
|
106
|
-
-
|
107
|
-
-
|
119
|
+
- Gemfile
|
120
|
+
- CHANGES.md
|
108
121
|
homepage: http://github.com/djberg96/file-find
|
109
122
|
licenses:
|
110
123
|
- Apache-2.0
|
111
|
-
metadata:
|
112
|
-
|
124
|
+
metadata:
|
125
|
+
homepage_uri: https://github.com/djberg96/file-find
|
126
|
+
bug_tracker_uri: https://github.com/djberg96/file-find/issues
|
127
|
+
changelog_uri: https://github.com/djberg96/file-find/blob/master/CHANGES.md
|
128
|
+
documentation_uri: https://github.com/djberg96/file-find/wiki
|
129
|
+
source_code_uri: https://github.com/djberg96/file-find
|
130
|
+
wiki_uri: https://github.com/djberg96/file-find/wiki
|
131
|
+
post_install_message:
|
113
132
|
rdoc_options: []
|
114
133
|
require_paths:
|
115
134
|
- lib
|
@@ -124,10 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
143
|
- !ruby/object:Gem::Version
|
125
144
|
version: '0'
|
126
145
|
requirements: []
|
127
|
-
|
128
|
-
|
129
|
-
signing_key:
|
146
|
+
rubygems_version: 3.0.3
|
147
|
+
signing_key:
|
130
148
|
specification_version: 4
|
131
149
|
summary: A better way to find files
|
132
150
|
test_files:
|
133
|
-
-
|
151
|
+
- spec/file_find_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|
data/README
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
This is a drop-in replacement for the find module currently in the standard
|
3
|
-
library. It is modeled on a typical 'find' command found on most Unix systems.
|
4
|
-
|
5
|
-
= Installation
|
6
|
-
|
7
|
-
gem install file-find
|
8
|
-
|
9
|
-
= Synopsis
|
10
|
-
require 'file/find'
|
11
|
-
|
12
|
-
rule = File::Find.new(
|
13
|
-
:pattern => "*.rb",
|
14
|
-
:follow => false,
|
15
|
-
:path => ['/usr/local/lib', '/opt/local/lib']
|
16
|
-
)
|
17
|
-
|
18
|
-
rule.find{ |f|
|
19
|
-
puts f
|
20
|
-
}
|
21
|
-
|
22
|
-
= Rationale
|
23
|
-
The current find module in the standard library is inadequate. It is, quite
|
24
|
-
frankly, not much more than a plain Dir.glob call. This library provides an
|
25
|
-
interface based on options typically available on your command line 'find'
|
26
|
-
command, thus allowing you much greater control over how you find your files.
|
27
|
-
|
28
|
-
= Options
|
29
|
-
* atime
|
30
|
-
* ctime
|
31
|
-
* follow
|
32
|
-
* ftype
|
33
|
-
* inum
|
34
|
-
* group (name or id)
|
35
|
-
* maxdepth
|
36
|
-
* mindepth
|
37
|
-
* mount
|
38
|
-
* mtime
|
39
|
-
* name (or 'pattern')
|
40
|
-
* path
|
41
|
-
* perm
|
42
|
-
* prune
|
43
|
-
* size
|
44
|
-
* user (name or id)
|
45
|
-
|
46
|
-
In addition to the above options, FileTest methods such as 'readable?' and
|
47
|
-
'writable?' may be used as keys, with true or false for their values.
|
48
|
-
|
49
|
-
See the RDoc documentation for more details about these options.
|
50
|
-
|
51
|
-
= Future Plans
|
52
|
-
None at this time. Please log any feature requests on the project page at:
|
53
|
-
|
54
|
-
http://github.com/djberg96/file-find
|
55
|
-
|
56
|
-
= Options I won't support
|
57
|
-
Generally speaking, anything that would require mucking around with C code
|
58
|
-
or is just too difficult to implement in a cross platform manner will not be
|
59
|
-
supported. These include the following options:
|
60
|
-
|
61
|
-
* acl/xattr - Way too difficult to implement in a cross platform manner, and
|
62
|
-
a rarely used option in practice.
|
63
|
-
|
64
|
-
* cpio/ncpio - I will not shell out to this or any other 3rd party
|
65
|
-
application.
|
66
|
-
|
67
|
-
* ls/print - Use Ruby's builtin printing methods to print as you see fit.
|
68
|
-
|
69
|
-
* ok - This is not interactive software.
|
70
|
-
|
71
|
-
= Known Issues
|
72
|
-
The :perm option is limited to 0644 and 0444 on MS Windows.
|
73
|
-
|
74
|
-
The :user, :group, and :inum options require the win32-file gem to work
|
75
|
-
properly on MS Windows. However, it is not officially a dependency.
|
76
|
-
|
77
|
-
= Bugs
|
78
|
-
None that I'm aware of beyond the ones mentioned in the Known Issues. Please
|
79
|
-
log any bug reports on the project page at:
|
80
|
-
|
81
|
-
http://github.com/djberg96/file-find
|
82
|
-
|
83
|
-
= Acknowledgements
|
84
|
-
* Richard Clamp's File::Find::Rule Perl module for additional ideas and
|
85
|
-
inspiration.
|
86
|
-
* Bill Kleb for ideas regarding name, group and perm enhancements.
|
87
|
-
* Hal Fulton for his implementation of symbolic permissions.
|
88
|
-
|
89
|
-
= License
|
90
|
-
Apache-2.0
|
91
|
-
|
92
|
-
= Copyright
|
93
|
-
(C) 2007-2018, Daniel J. Berger, All Rights Reserved
|
94
|
-
|
95
|
-
= Author
|
96
|
-
Daniel J. Berger
|
data/test/test_file_find.rb
DELETED
@@ -1,568 +0,0 @@
|
|
1
|
-
######################################################################
|
2
|
-
# test_file_find.rb
|
3
|
-
#
|
4
|
-
# Test case for the File::Find package. You should run this via the
|
5
|
-
# 'rake test' task.
|
6
|
-
######################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'fileutils'
|
9
|
-
require 'file/find'
|
10
|
-
require 'sys/admin'
|
11
|
-
|
12
|
-
if File::ALT_SEPARATOR
|
13
|
-
require 'win32/file'
|
14
|
-
require 'win32/security'
|
15
|
-
end
|
16
|
-
|
17
|
-
include FileUtils
|
18
|
-
|
19
|
-
class TC_File_Find < Test::Unit::TestCase
|
20
|
-
def self.startup
|
21
|
-
Dir.chdir(File.dirname(File.expand_path(__FILE__)))
|
22
|
-
|
23
|
-
@@windows = File::ALT_SEPARATOR
|
24
|
-
@@jruby = RUBY_PLATFORM.match('java')
|
25
|
-
|
26
|
-
if @@windows
|
27
|
-
@@elevated = Win32::Security.elevated_security?
|
28
|
-
if @@elevated
|
29
|
-
@@loguser = Sys::Admin.get_group("Administrators", :LocalAccount => true)
|
30
|
-
else
|
31
|
-
@@loguser = Sys::Admin.get_user(Sys::Admin.get_login, :LocalAccount => true)
|
32
|
-
end
|
33
|
-
else
|
34
|
-
@@loguser = Sys::Admin.get_user(Sys::Admin.get_login)
|
35
|
-
@@logroup = Sys::Admin.get_group(@@loguser.gid)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def setup
|
40
|
-
@file_rb = 'test1.rb'
|
41
|
-
@file_txt1 = 'test1.txt'
|
42
|
-
@file_txt2 = 'foo.txt'
|
43
|
-
@file_doc = 'foo.doc'
|
44
|
-
@directory1 = 'dir1'
|
45
|
-
@directory2 = 'dir2'
|
46
|
-
|
47
|
-
File.open(@file_rb, 'w'){}
|
48
|
-
File.open(@file_txt1, 'w'){}
|
49
|
-
File.open(@file_txt2, 'w'){}
|
50
|
-
File.open(@file_doc, 'w'){}
|
51
|
-
|
52
|
-
@link1 = 'link1'
|
53
|
-
|
54
|
-
if @@windows
|
55
|
-
File.symlink(@file_rb, @link1) if @@elevated
|
56
|
-
else
|
57
|
-
File.symlink(@file_rb, @link1)
|
58
|
-
end
|
59
|
-
|
60
|
-
Dir.mkdir(@directory1) unless File.exist?(@directory1)
|
61
|
-
Dir.mkdir(@directory2) unless File.exist?(@directory2)
|
62
|
-
|
63
|
-
File.open(File.join(@directory1, 'bar.txt'), 'w'){}
|
64
|
-
File.open(File.join(@directory2, 'baz.txt'), 'w'){}
|
65
|
-
|
66
|
-
@rule1 = File::Find.new(:name => '*.txt')
|
67
|
-
@rule2 = File::Find.new
|
68
|
-
end
|
69
|
-
|
70
|
-
test "version constant is set to expected value" do
|
71
|
-
assert_equal('0.4.0', File::Find::VERSION)
|
72
|
-
assert_true(File::Find::VERSION.frozen?)
|
73
|
-
end
|
74
|
-
|
75
|
-
test "path accessor basic functionality" do
|
76
|
-
assert_respond_to(@rule1, :path)
|
77
|
-
assert_respond_to(@rule1, :path=)
|
78
|
-
end
|
79
|
-
|
80
|
-
test "path method returns expected value" do
|
81
|
-
assert_equal(Dir.pwd, @rule1.path)
|
82
|
-
end
|
83
|
-
|
84
|
-
test "options accessor basic functionality" do
|
85
|
-
assert_respond_to(@rule1, :options)
|
86
|
-
assert_respond_to(@rule1, :options=)
|
87
|
-
end
|
88
|
-
|
89
|
-
test "options method returns expected value" do
|
90
|
-
assert_equal({:name => '*.txt'}, @rule1.options)
|
91
|
-
end
|
92
|
-
|
93
|
-
test "atime accessor basic functionality" do
|
94
|
-
assert_respond_to(@rule1, :atime)
|
95
|
-
assert_respond_to(@rule1, :atime=)
|
96
|
-
end
|
97
|
-
|
98
|
-
test "atime method returns expected default value" do
|
99
|
-
assert_nil(@rule1.atime)
|
100
|
-
end
|
101
|
-
|
102
|
-
test "find with atime option works as expected" do
|
103
|
-
rule1 = File::Find.new(:name => "*.rb", :atime => 0)
|
104
|
-
rule2 = File::Find.new(:name => "*.rb", :atime => 1)
|
105
|
-
|
106
|
-
assert_false(rule1.find.empty?)
|
107
|
-
assert_true(rule2.find.empty?)
|
108
|
-
end
|
109
|
-
|
110
|
-
test "ctime accessor basic functionality" do
|
111
|
-
assert_respond_to(@rule1, :ctime)
|
112
|
-
assert_respond_to(@rule1, :ctime=)
|
113
|
-
end
|
114
|
-
|
115
|
-
test "ctime method returns expected default value" do
|
116
|
-
assert_nil(@rule1.ctime)
|
117
|
-
end
|
118
|
-
|
119
|
-
test "find with ctime option works as expected" do
|
120
|
-
rule1 = File::Find.new(:name => "*.rb", :ctime => 0)
|
121
|
-
rule2 = File::Find.new(:name => "*.rb", :ctime => 1)
|
122
|
-
|
123
|
-
assert_false(rule1.find.empty?)
|
124
|
-
assert_true(rule2.find.empty?)
|
125
|
-
end
|
126
|
-
|
127
|
-
test "find method basic functionality" do
|
128
|
-
assert_respond_to(@rule1, :find)
|
129
|
-
assert_nothing_raised{ @rule1.find }
|
130
|
-
end
|
131
|
-
|
132
|
-
test "find method returns expected value" do
|
133
|
-
assert_kind_of(Array, @rule1.find)
|
134
|
-
assert_nil(@rule1.find{})
|
135
|
-
end
|
136
|
-
|
137
|
-
test "filetest accessor basic functionality" do
|
138
|
-
assert_respond_to(@rule1, :filetest)
|
139
|
-
assert_respond_to(@rule1, :filetest=)
|
140
|
-
assert_nothing_raised{ @rule1.filetest }
|
141
|
-
end
|
142
|
-
|
143
|
-
test "filetest method returns expected value" do
|
144
|
-
assert_kind_of(Array, @rule1.filetest)
|
145
|
-
end
|
146
|
-
|
147
|
-
test "valid filetest options work as expected" do
|
148
|
-
assert_nothing_raised{ File::Find.new(:readable? => true) }
|
149
|
-
assert_nothing_raised{ File::Find.new(:writable? => true) }
|
150
|
-
end
|
151
|
-
|
152
|
-
test "find method works with filetest option" do
|
153
|
-
rule = File::Find.new(:name => "*.doc", :writable? => true)
|
154
|
-
File.chmod(0644, @file_doc)
|
155
|
-
|
156
|
-
assert_equal([@file_doc], rule.find.map{ |f| File.basename(f) })
|
157
|
-
|
158
|
-
File.chmod(0444, @file_doc)
|
159
|
-
|
160
|
-
assert_equal([], rule.find)
|
161
|
-
end
|
162
|
-
|
163
|
-
test "mtime accessor basic functionality" do
|
164
|
-
assert_respond_to(@rule1, :mtime)
|
165
|
-
assert_respond_to(@rule1, :mtime=)
|
166
|
-
end
|
167
|
-
|
168
|
-
test "mtime method returns expected default value" do
|
169
|
-
assert_nil(@rule1.mtime)
|
170
|
-
end
|
171
|
-
|
172
|
-
test "find with mtime option works as expected" do
|
173
|
-
rule1 = File::Find.new(:name => "*.rb", :mtime => 0)
|
174
|
-
rule2 = File::Find.new(:name => "*.rb", :mtime => 1)
|
175
|
-
|
176
|
-
assert_false(rule1.find.empty?)
|
177
|
-
assert_true(rule2.find.empty?)
|
178
|
-
end
|
179
|
-
|
180
|
-
test "ftype accessor basic functionality" do
|
181
|
-
assert_respond_to(@rule1, :ftype)
|
182
|
-
assert_respond_to(@rule1, :ftype=)
|
183
|
-
end
|
184
|
-
|
185
|
-
test "ftype method returns expected default value" do
|
186
|
-
assert_nil(@rule1.ftype)
|
187
|
-
end
|
188
|
-
|
189
|
-
test "ftype method works as expected" do
|
190
|
-
rule1 = File::Find.new(:name => "*.rb", :ftype => "file")
|
191
|
-
rule2 = File::Find.new(:name => "*.rb", :ftype => "characterSpecial")
|
192
|
-
|
193
|
-
assert_false(rule1.find.empty?)
|
194
|
-
assert_true(rule2.find.empty?)
|
195
|
-
end
|
196
|
-
|
197
|
-
test "group accessor basic functionality" do
|
198
|
-
assert_respond_to(@rule1, :group)
|
199
|
-
assert_respond_to(@rule1, :group=)
|
200
|
-
end
|
201
|
-
|
202
|
-
test "group method returns expected default value" do
|
203
|
-
assert_nil(@rule1.group)
|
204
|
-
end
|
205
|
-
|
206
|
-
# TODO: Update test for Windows
|
207
|
-
test "find with numeric group id works as expected" do
|
208
|
-
omit_if(@@windows, 'group test skipped on MS Windows')
|
209
|
-
@rule1 = File::Find.new(:name => '*.doc', :group => @@loguser.gid)
|
210
|
-
assert_equal([File.expand_path(@file_doc)], @rule1.find)
|
211
|
-
end
|
212
|
-
|
213
|
-
# TODO: Update test for Windows
|
214
|
-
test "find with string group id works as expected" do
|
215
|
-
omit_if(@@windows, 'group test skipped on MS Windows')
|
216
|
-
@rule1 = File::Find.new(:name => '*.doc', :group => @@logroup.name)
|
217
|
-
assert_equal([File.expand_path(@file_doc)], @rule1.find)
|
218
|
-
end
|
219
|
-
|
220
|
-
test "find with bogus group returns empty results" do
|
221
|
-
omit_if(@@windows, 'group test skipped on MS Windows')
|
222
|
-
@rule1 = File::Find.new(:name => '*.doc', :group => 'totallybogus')
|
223
|
-
@rule2 = File::Find.new(:name => '*.doc', :group => 99999999)
|
224
|
-
assert_equal([], @rule1.find)
|
225
|
-
assert_equal([], @rule2.find)
|
226
|
-
end
|
227
|
-
|
228
|
-
test "inum accessor basic functionality" do
|
229
|
-
assert_respond_to(@rule1, :inum)
|
230
|
-
assert_respond_to(@rule1, :inum=)
|
231
|
-
end
|
232
|
-
|
233
|
-
test "inum method returns expected default value" do
|
234
|
-
assert_nil(@rule1.inum)
|
235
|
-
end
|
236
|
-
|
237
|
-
test "follow accessor basic functionality" do
|
238
|
-
assert_respond_to(@rule1, :follow)
|
239
|
-
assert_respond_to(@rule1, :follow=)
|
240
|
-
end
|
241
|
-
|
242
|
-
test "follow method returns expected default value" do
|
243
|
-
assert_true(@rule1.follow)
|
244
|
-
end
|
245
|
-
|
246
|
-
test "links accessor basic functionality" do
|
247
|
-
assert_respond_to(@rule1, :links)
|
248
|
-
assert_respond_to(@rule1, :links=)
|
249
|
-
end
|
250
|
-
|
251
|
-
test "links method returns expected default value" do
|
252
|
-
assert_nil(@rule1.links)
|
253
|
-
end
|
254
|
-
|
255
|
-
test "links method returns expected result" do
|
256
|
-
omit_if(@@windows && !@@elevated)
|
257
|
-
@rule1 = File::Find.new(:name => '*.rb', :links => 2)
|
258
|
-
@rule2 = File::Find.new(:name => '*.doc', :links => 1)
|
259
|
-
|
260
|
-
assert_equal([], @rule1.find)
|
261
|
-
assert_equal([File.expand_path(@file_doc)], @rule2.find)
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_maxdepth_basic
|
265
|
-
assert_respond_to(@rule1, :maxdepth)
|
266
|
-
assert_respond_to(@rule1, :maxdepth=)
|
267
|
-
assert_nil(@rule1.maxdepth)
|
268
|
-
end
|
269
|
-
|
270
|
-
# This test is a little uglier because we actually check to make sure
|
271
|
-
# we're looking at the right subdir, not just a filename shows up.
|
272
|
-
# I did this because I'm a little paranoid about the directory
|
273
|
-
# not getting mangled. - jlawler.
|
274
|
-
#
|
275
|
-
test "find method works on dirs that contain brackets" do
|
276
|
-
omit_if(@@windows, 'dirs with brackets test skipped on MS Windows')
|
277
|
-
|
278
|
-
bracket_files = [ 'bracket/a[1]/a.foo', 'bracket/a [2] /b.foo', 'bracket/[a] b [c]/d.foo' ].sort
|
279
|
-
bracket_paths = [ 'bracket/a[1]', 'bracket/a [2] ', 'bracket/[a] b [c]', 'bracket/[z] x' ].sort
|
280
|
-
|
281
|
-
bracket_paths.each{ |e| mkpath(e) }
|
282
|
-
bracket_files.each{ |e| touch(e) }
|
283
|
-
|
284
|
-
@file_rule = File::Find.new(
|
285
|
-
:ftype => 'file',
|
286
|
-
:path => ['bracket']
|
287
|
-
)
|
288
|
-
|
289
|
-
@dir_rule = File::Find.new(
|
290
|
-
:path => ['bracket'],
|
291
|
-
:ftype => 'directory'
|
292
|
-
)
|
293
|
-
|
294
|
-
file_results = @file_rule.find.sort
|
295
|
-
|
296
|
-
assert_equal(bracket_files.size,file_results.size)
|
297
|
-
path = file_results.first.chomp(bracket_files.first)
|
298
|
-
|
299
|
-
# Confirm the first thing in results is the first thing in bracket_paths
|
300
|
-
assert_not_equal(path, file_results.first)
|
301
|
-
assert_equal(bracket_files, file_results.map{ |e| e.sub(path,'') }.sort )
|
302
|
-
assert_equal(bracket_paths, @dir_rule.find.sort )
|
303
|
-
end
|
304
|
-
|
305
|
-
test "find with maxdepth option returns expected results" do
|
306
|
-
mkpath('a1/a2/a3')
|
307
|
-
touch('a1/a.foo')
|
308
|
-
touch('a1/a2/b.foo')
|
309
|
-
touch('a1/a2/c.foo')
|
310
|
-
touch('a1/a2/a3/d.foo')
|
311
|
-
touch('a1/a2/a3/e.foo')
|
312
|
-
touch('a1/a2/a3/f.foo')
|
313
|
-
|
314
|
-
@rule2.pattern = "*.foo"
|
315
|
-
@rule2.maxdepth = 1
|
316
|
-
assert_equal([], @rule2.find)
|
317
|
-
|
318
|
-
@rule2.maxdepth = 2
|
319
|
-
assert_equal(['a.foo'], @rule2.find.map{ |e| File.basename(e) })
|
320
|
-
|
321
|
-
@rule2.maxdepth = 3
|
322
|
-
assert_equal(['a.foo', 'b.foo', 'c.foo'], @rule2.find.map{ |e| File.basename(e) }.sort)
|
323
|
-
|
324
|
-
@rule2.maxdepth = nil
|
325
|
-
assert_equal(
|
326
|
-
['a.foo', 'b.foo', 'c.foo', 'd.foo', 'e.foo', 'f.foo'],
|
327
|
-
@rule2.find.map{ |e| File.basename(e) }.sort
|
328
|
-
)
|
329
|
-
end
|
330
|
-
|
331
|
-
test "find with maxdepth option returns expected results for directories" do
|
332
|
-
mkpath('a/b/c')
|
333
|
-
@rule2.pattern = "c"
|
334
|
-
|
335
|
-
@rule2.maxdepth = 1
|
336
|
-
assert_equal([], @rule2.find)
|
337
|
-
|
338
|
-
@rule2.maxdepth = 2
|
339
|
-
assert_equal([], @rule2.find)
|
340
|
-
|
341
|
-
@rule2.maxdepth = 3
|
342
|
-
assert_equal(['c'], @rule2.find.map{ |e| File.basename(e) })
|
343
|
-
end
|
344
|
-
|
345
|
-
test "mindepth accessor basic functionality" do
|
346
|
-
assert_respond_to(@rule1, :mindepth)
|
347
|
-
assert_respond_to(@rule1, :mindepth=)
|
348
|
-
end
|
349
|
-
|
350
|
-
test "mindepth method returns expected default value" do
|
351
|
-
assert_nil(@rule1.mindepth)
|
352
|
-
end
|
353
|
-
|
354
|
-
test "find with mindepth option returns expected results" do
|
355
|
-
mkpath('a1/a2/a3')
|
356
|
-
touch('z.min')
|
357
|
-
touch('a1/a.min')
|
358
|
-
touch('a1/a2/b.min')
|
359
|
-
touch('a1/a2/c.min')
|
360
|
-
touch('a1/a2/a3/d.min')
|
361
|
-
touch('a1/a2/a3/e.min')
|
362
|
-
touch('a1/a2/a3/f.min')
|
363
|
-
|
364
|
-
@rule2.pattern = "*.min"
|
365
|
-
|
366
|
-
@rule2.mindepth = 0
|
367
|
-
assert_equal(
|
368
|
-
['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min'],
|
369
|
-
@rule2.find.map{ |e| File.basename(e) }.sort
|
370
|
-
)
|
371
|
-
|
372
|
-
@rule2.mindepth = 1
|
373
|
-
assert_equal(
|
374
|
-
['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min'],
|
375
|
-
@rule2.find.map{ |e| File.basename(e) }.sort
|
376
|
-
)
|
377
|
-
|
378
|
-
@rule2.mindepth = 2
|
379
|
-
assert_equal(
|
380
|
-
['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min'],
|
381
|
-
@rule2.find.map{ |e| File.basename(e) }.sort
|
382
|
-
)
|
383
|
-
|
384
|
-
@rule2.mindepth = 3
|
385
|
-
assert_equal(
|
386
|
-
['b.min', 'c.min', 'd.min', 'e.min', 'f.min'],
|
387
|
-
@rule2.find.map{ |e| File.basename(e) }.sort
|
388
|
-
)
|
389
|
-
|
390
|
-
@rule2.mindepth = 4
|
391
|
-
assert_equal(['d.min', 'e.min', 'f.min'], @rule2.find.map{ |e| File.basename(e) }.sort)
|
392
|
-
|
393
|
-
@rule2.mindepth = 5
|
394
|
-
assert_equal([], @rule2.find.map{ |e| File.basename(e) })
|
395
|
-
end
|
396
|
-
|
397
|
-
test "find with mindepth option returns expected results for directories" do
|
398
|
-
mkpath('a/b/c')
|
399
|
-
@rule2.pattern = "a"
|
400
|
-
|
401
|
-
@rule2.mindepth = 1
|
402
|
-
assert_equal(['a'], @rule2.find.map{ |e| File.basename(e) })
|
403
|
-
|
404
|
-
@rule2.mindepth = 2
|
405
|
-
assert_equal([], @rule2.find)
|
406
|
-
|
407
|
-
@rule2.mindepth = 3
|
408
|
-
assert_equal([], @rule2.find)
|
409
|
-
end
|
410
|
-
|
411
|
-
test "mount accessor basic functionality" do
|
412
|
-
assert_respond_to(@rule1, :mount)
|
413
|
-
assert_respond_to(@rule1, :mount=)
|
414
|
-
end
|
415
|
-
|
416
|
-
test "mount method returns expected default value" do
|
417
|
-
assert_nil(@rule1.mount)
|
418
|
-
end
|
419
|
-
|
420
|
-
test "name accessor basic functionality" do
|
421
|
-
assert_respond_to(@rule1, :name)
|
422
|
-
assert_respond_to(@rule1, :name=)
|
423
|
-
end
|
424
|
-
|
425
|
-
test "name method returns expected default value" do
|
426
|
-
assert_equal('*.txt', @rule1.name)
|
427
|
-
end
|
428
|
-
|
429
|
-
test "pattern accessor basic functionality" do
|
430
|
-
assert_respond_to(@rule1, :pattern)
|
431
|
-
assert_respond_to(@rule1, :pattern=)
|
432
|
-
end
|
433
|
-
|
434
|
-
test "pattern is an alias for name" do
|
435
|
-
assert_alias_method(@rule1, :name, :pattern)
|
436
|
-
assert_alias_method(@rule1, :name=, :pattern=)
|
437
|
-
end
|
438
|
-
|
439
|
-
test "perm accessor basic functionality" do
|
440
|
-
assert_respond_to(@rule1, :perm)
|
441
|
-
assert_respond_to(@rule1, :perm=)
|
442
|
-
end
|
443
|
-
|
444
|
-
test "perm method returns expected default value" do
|
445
|
-
assert_nil(@rule1.perm)
|
446
|
-
end
|
447
|
-
|
448
|
-
test "perm method returns expected results" do
|
449
|
-
File.chmod(0444, @file_rb)
|
450
|
-
File.chmod(0644, @file_txt1)
|
451
|
-
|
452
|
-
results = File::Find.new(:name => "test1*", :perm => 0644).find
|
453
|
-
|
454
|
-
assert_equal(1, results.length)
|
455
|
-
assert_equal('test1.txt', File.basename(results.first))
|
456
|
-
end
|
457
|
-
|
458
|
-
test "perm method works with symbolic permissions" do
|
459
|
-
omit_if(@@windows, 'symbolic perm test skipped on MS Windows')
|
460
|
-
|
461
|
-
File.chmod(0664, @file_rb) # test1.rb
|
462
|
-
File.chmod(0644, @file_txt1) # test1.txt
|
463
|
-
results1 = File::Find.new(:name => "test1*", :perm => "g=rw").find
|
464
|
-
results2 = File::Find.new(:name => "test1*", :perm => "u=rw").find
|
465
|
-
|
466
|
-
assert_equal(1, results1.length)
|
467
|
-
assert_equal(2, results2.length)
|
468
|
-
assert_equal('test1.rb', File.basename(results1.first))
|
469
|
-
assert_equal(['test1.rb', 'test1.txt'], results2.map{ |e| File.basename(e) }.sort)
|
470
|
-
end
|
471
|
-
|
472
|
-
test "prune accessor basic functionality" do
|
473
|
-
assert_respond_to(@rule1, :prune)
|
474
|
-
assert_respond_to(@rule1, :prune=)
|
475
|
-
end
|
476
|
-
|
477
|
-
test "prune method returns expected default value" do
|
478
|
-
assert_nil(@rule1.prune)
|
479
|
-
end
|
480
|
-
|
481
|
-
test "find method with prune option works as expected" do
|
482
|
-
rule = File::Find.new(:name => "*.txt", :prune => 'foo')
|
483
|
-
assert_equal('test1.txt', File.basename(rule.find.first))
|
484
|
-
end
|
485
|
-
|
486
|
-
test "size accessor basic functionality" do
|
487
|
-
assert_respond_to(@rule1, :size)
|
488
|
-
assert_respond_to(@rule1, :size=)
|
489
|
-
end
|
490
|
-
|
491
|
-
test "size method returns expected default value" do
|
492
|
-
assert_nil(@rule1.size)
|
493
|
-
end
|
494
|
-
|
495
|
-
test "user accessor basic functionality" do
|
496
|
-
assert_respond_to(@rule1, :user)
|
497
|
-
assert_respond_to(@rule1, :user=)
|
498
|
-
end
|
499
|
-
|
500
|
-
test "user method returns expected default value" do
|
501
|
-
assert_nil(@rule1.user)
|
502
|
-
end
|
503
|
-
|
504
|
-
test "user method works with numeric id as expected" do
|
505
|
-
if @@windows && @@elevated
|
506
|
-
uid = @@loguser.gid # Windows assigns the group if any member is an admin
|
507
|
-
else
|
508
|
-
uid = @@loguser.uid
|
509
|
-
end
|
510
|
-
|
511
|
-
@rule1 = File::Find.new(:name => '*.doc', :user => uid)
|
512
|
-
assert_equal([File.expand_path(@file_doc)], @rule1.find)
|
513
|
-
end
|
514
|
-
|
515
|
-
test "user method works with string as expected" do
|
516
|
-
omit_if(@@windows && @@elevated)
|
517
|
-
@rule1 = File::Find.new(:name => '*.doc', :user => @@loguser.name)
|
518
|
-
assert_equal([File.expand_path(@file_doc)], @rule1.find)
|
519
|
-
end
|
520
|
-
|
521
|
-
test "find method with user option using invalid user returns expected results" do
|
522
|
-
@rule1 = File::Find.new(:name => '*.doc', :user => 'totallybogus')
|
523
|
-
@rule2 = File::Find.new(:name => '*.doc', :user => 99999999)
|
524
|
-
assert_equal([], @rule1.find)
|
525
|
-
assert_equal([], @rule2.find)
|
526
|
-
end
|
527
|
-
|
528
|
-
test "previous method basic functionality" do
|
529
|
-
assert_respond_to(@rule1, :previous)
|
530
|
-
end
|
531
|
-
|
532
|
-
test "an error is raised if the path does not exist" do
|
533
|
-
assert_raise(Errno::ENOENT){ File::Find.new(:path => '/bogus/dir').find }
|
534
|
-
end
|
535
|
-
|
536
|
-
test "an error is raised if an invalid option is passed" do
|
537
|
-
assert_raise(ArgumentError){ File::Find.new(:bogus => 1) }
|
538
|
-
assert_raise(ArgumentError){ File::Find.new(:bogus? => true) }
|
539
|
-
end
|
540
|
-
|
541
|
-
def teardown
|
542
|
-
rm_rf(@file_rb)
|
543
|
-
rm_rf(@file_txt1)
|
544
|
-
rm_rf(@file_txt2)
|
545
|
-
rm_rf(@file_doc)
|
546
|
-
rm_rf(@directory1)
|
547
|
-
rm_rf(@directory2)
|
548
|
-
rm_rf(@link1) #unless @@windows
|
549
|
-
rm_rf('a')
|
550
|
-
rm_rf('a1')
|
551
|
-
rm_rf('bracket')
|
552
|
-
rm_rf('z.min') if File.exist?('z.min')
|
553
|
-
|
554
|
-
@rule1 = nil
|
555
|
-
@rule2 = nil
|
556
|
-
@file_rb = nil
|
557
|
-
@file_txt1 = nil
|
558
|
-
@file_txt2 = nil
|
559
|
-
@file_doc = nil
|
560
|
-
end
|
561
|
-
|
562
|
-
def self.shutdown
|
563
|
-
@@windows = nil
|
564
|
-
@@jruby = nil
|
565
|
-
@@elevated = nil if @@windows
|
566
|
-
@@logroup = nil unless @@windows
|
567
|
-
end
|
568
|
-
end
|