file-find 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/README +7 -1
- data/lib/file/find.rb +48 -7
- data/test/{tc_find.rb → test_file_find.rb} +85 -18
- metadata +63 -37
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 0.2.2 - 19-Nov-2008
|
2
|
+
* The :user and :group options now accept a name or a numeric id. Thanks go
|
3
|
+
to Bill Kleb for the suggestion.
|
4
|
+
* Fixed yet another path bug for MS Windows.
|
5
|
+
* Updated platform check to use CONFIG instead of RUBY_PLATFORM, because the
|
6
|
+
latter does not work as I intended with other implementations, e.g. JRuby.
|
7
|
+
* Added sys-admin and test-unit as prerequisites.
|
8
|
+
* Added tests for the :user and :group options.
|
9
|
+
|
1
10
|
== 0.2.1 - 4-Oct-2007
|
2
11
|
* Added the File::Find#previous method, which lets you see the previous
|
3
12
|
match, if any.
|
data/README
CHANGED
@@ -49,8 +49,10 @@ http://www.rubyforge.org/projects/shards.
|
|
49
49
|
|
50
50
|
Some specific things I plan on adding:
|
51
51
|
|
52
|
+
* symbolic permissions for the :perm option
|
52
53
|
* exec
|
53
54
|
* links
|
55
|
+
* support for :user and :group on MS Windows
|
54
56
|
|
55
57
|
= Options I won't support
|
56
58
|
Generally speaking, anything that would require mucking around with C code
|
@@ -79,6 +81,10 @@ The 'perm' option does not work on MS Windows, even for its limited subset of
|
|
79
81
|
permissions, i.e. 664 and 666. This is arguably a bug in Ruby's
|
80
82
|
File::Stat.mode method on MS Windows.
|
81
83
|
|
84
|
+
The 'user' and 'group' options are not currently supported on MS Windows.
|
85
|
+
This can be supported, but will require changes in the win32-file and
|
86
|
+
win32-file-stat libraries (which would then become dependencies).
|
87
|
+
|
82
88
|
= Bugs
|
83
89
|
None that I'm aware of. Please log any bug reports on the project page at
|
84
90
|
http://www.rubyforge.org/projects/shards.
|
@@ -91,7 +97,7 @@ http://www.rubyforge.org/projects/shards.
|
|
91
97
|
Ruby's
|
92
98
|
|
93
99
|
= Copyright
|
94
|
-
(C) 2007, Daniel J. Berger, All Rights Reserved
|
100
|
+
(C) 2007-2008, Daniel J. Berger, All Rights Reserved
|
95
101
|
|
96
102
|
= Author
|
97
103
|
Daniel J. Berger
|
data/lib/file/find.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'date'
|
2
|
+
require 'rbconfig'
|
3
|
+
require 'sys/admin'
|
4
|
+
include Config
|
5
|
+
include Sys
|
2
6
|
|
3
7
|
class File::Find
|
4
|
-
# The version of this
|
5
|
-
VERSION = '0.2.
|
8
|
+
# The version of this library
|
9
|
+
VERSION = '0.2.2'
|
6
10
|
|
7
11
|
# :stopdoc:
|
8
12
|
VALID_OPTIONS = %w/
|
@@ -45,7 +49,10 @@ class File::Find
|
|
45
49
|
#
|
46
50
|
attr_accessor :ctime
|
47
51
|
|
48
|
-
# Limits searches to files that belong to a specific group
|
52
|
+
# Limits searches to files that belong to a specific group, where the
|
53
|
+
# group can be either a group name or ID.
|
54
|
+
#
|
55
|
+
# Not currently supported on MS Windows.
|
49
56
|
#
|
50
57
|
attr_accessor :group
|
51
58
|
|
@@ -74,6 +81,8 @@ class File::Find
|
|
74
81
|
# group, and world settings are used. Do not use a leading 0 in the values
|
75
82
|
# that you supply, e.g. use 755 not 0755.
|
76
83
|
#
|
84
|
+
# Not currently supported on MS Windows.
|
85
|
+
#
|
77
86
|
attr_accessor :perm
|
78
87
|
|
79
88
|
# Skips files or directories that match the string provided as an argument.
|
@@ -87,7 +96,10 @@ class File::Find
|
|
87
96
|
#
|
88
97
|
attr_accessor :size
|
89
98
|
|
90
|
-
# Limits searches to files that belong to a specific user
|
99
|
+
# Limits searches to files that belong to a specific user, where the user
|
100
|
+
# can be either a user name or an ID.
|
101
|
+
#
|
102
|
+
# Not currently supported on MS Windows.
|
91
103
|
#
|
92
104
|
attr_accessor :user
|
93
105
|
|
@@ -102,6 +114,14 @@ class File::Find
|
|
102
114
|
# object serve as the rules for determining what files the File::Find#find
|
103
115
|
# method will search for.
|
104
116
|
#
|
117
|
+
# Example:
|
118
|
+
#
|
119
|
+
# rule = File::Find.new(
|
120
|
+
# :name => "*.rb",
|
121
|
+
# :follow => false,
|
122
|
+
# :path => ['/usr/local/lib', '/opt/local/lib']
|
123
|
+
# )
|
124
|
+
#
|
105
125
|
def initialize(options = {})
|
106
126
|
@options = options
|
107
127
|
|
@@ -128,6 +148,18 @@ class File::Find
|
|
128
148
|
# In block form, yields each file in turn that matches the specified rules.
|
129
149
|
# In non-block form it will return an array of matches instead.
|
130
150
|
#
|
151
|
+
# Example:
|
152
|
+
#
|
153
|
+
# rule = File::Find.new(
|
154
|
+
# :name => "*.rb",
|
155
|
+
# :follow => false,
|
156
|
+
# :path => ['/usr/local/lib', '/opt/local/lib']
|
157
|
+
# )
|
158
|
+
#
|
159
|
+
# rule.find{ |f|
|
160
|
+
# puts f
|
161
|
+
# }
|
162
|
+
#
|
131
163
|
def find
|
132
164
|
results = [] unless block_given?
|
133
165
|
paths = @path.to_a
|
@@ -179,6 +211,7 @@ class File::Find
|
|
179
211
|
# Dir[] doesn't like backslashes
|
180
212
|
if File::ALT_SEPARATOR
|
181
213
|
file.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
|
214
|
+
glob.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
|
182
215
|
end
|
183
216
|
|
184
217
|
next unless Dir[glob].include?(file)
|
@@ -200,10 +233,14 @@ class File::Find
|
|
200
233
|
end
|
201
234
|
|
202
235
|
if @group
|
203
|
-
|
236
|
+
if @group.is_a?(String)
|
237
|
+
next unless Admin.get_group(stat_info.gid).name == @group
|
238
|
+
else
|
239
|
+
next unless stat_info.gid == @group
|
240
|
+
end
|
204
241
|
end
|
205
242
|
|
206
|
-
unless
|
243
|
+
unless CONFIG['host_os'] =~ /windows|mswin/i
|
207
244
|
if @inum
|
208
245
|
next unless stat_info.ino == @inum
|
209
246
|
end
|
@@ -237,7 +274,11 @@ class File::Find
|
|
237
274
|
end
|
238
275
|
|
239
276
|
if @user
|
240
|
-
|
277
|
+
if @user.is_a?(String)
|
278
|
+
next unless Admin.get_user(stat_info.uid).name == @user
|
279
|
+
else
|
280
|
+
next unless stat_info.uid == @user
|
281
|
+
end
|
241
282
|
end
|
242
283
|
|
243
284
|
if block_given?
|
@@ -1,28 +1,41 @@
|
|
1
1
|
######################################################################
|
2
|
-
#
|
2
|
+
# test_file_find.rb
|
3
3
|
#
|
4
4
|
# Test case for the File::Find package. You should run this via the
|
5
5
|
# 'rake test' task.
|
6
6
|
######################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
7
10
|
require 'test/unit'
|
8
11
|
require 'fileutils'
|
9
12
|
require 'file/find'
|
13
|
+
require 'rbconfig'
|
14
|
+
require 'sys/admin'
|
15
|
+
include Config
|
10
16
|
|
11
17
|
class TC_File_Find < Test::Unit::TestCase
|
12
|
-
|
18
|
+
def self.startup
|
19
|
+
Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
|
20
|
+
@@windows = CONFIG['host_os'] =~ /windows|mswin/i
|
21
|
+
@@loguser = Sys::Admin.get_user(Admin.get_login) unless @@windows
|
22
|
+
@@logroup = Sys::Admin.get_group(@@loguser.gid) unless @@windows
|
23
|
+
end
|
13
24
|
|
14
25
|
def setup
|
15
26
|
@file1 = 'test1.rb'
|
16
27
|
@file2 = 'test1.txt'
|
17
28
|
@file3 = 'foo.txt'
|
29
|
+
@file4 = 'foo.doc'
|
18
30
|
@dir1 = 'dir1'
|
19
31
|
@dir2 = 'dir2'
|
20
32
|
|
21
33
|
File.open(@file1, 'w'){}
|
22
34
|
File.open(@file2, 'w'){}
|
23
35
|
File.open(@file3, 'w'){}
|
36
|
+
File.open(@file4, 'w'){}
|
24
37
|
|
25
|
-
unless
|
38
|
+
unless @@windows
|
26
39
|
@link1 = 'link1'
|
27
40
|
File.symlink(@file1, @link1)
|
28
41
|
end
|
@@ -33,11 +46,12 @@ class TC_File_Find < Test::Unit::TestCase
|
|
33
46
|
File.open(File.join(@dir1, 'bar.txt'), 'w'){}
|
34
47
|
File.open(File.join(@dir2, 'baz.txt'), 'w'){}
|
35
48
|
|
36
|
-
@rule1 = File::Find.new(:name => '*.
|
49
|
+
@rule1 = File::Find.new(:name => '*.txt')
|
50
|
+
@rule2 = File::Find.new
|
37
51
|
end
|
38
52
|
|
39
53
|
def test_version
|
40
|
-
assert_equal('0.2.
|
54
|
+
assert_equal('0.2.2', File::Find::VERSION)
|
41
55
|
end
|
42
56
|
|
43
57
|
def test_path
|
@@ -49,7 +63,7 @@ class TC_File_Find < Test::Unit::TestCase
|
|
49
63
|
def test_options
|
50
64
|
assert_respond_to(@rule1, :options)
|
51
65
|
assert_respond_to(@rule1, :options=)
|
52
|
-
assert_equal({:name => '*.
|
66
|
+
assert_equal({:name => '*.txt'}, @rule1.options)
|
53
67
|
end
|
54
68
|
|
55
69
|
def test_atime_basic
|
@@ -100,6 +114,26 @@ class TC_File_Find < Test::Unit::TestCase
|
|
100
114
|
assert_nil(@rule1.group)
|
101
115
|
end
|
102
116
|
|
117
|
+
def test_group_with_numeric_id
|
118
|
+
omit_if(@@windows, 'group test skipped on MS Windows')
|
119
|
+
@rule1 = File::Find.new(:name => '*.doc', :group => @@loguser.gid)
|
120
|
+
assert_equal([File.expand_path(@file4)], @rule1.find)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_group_with_string
|
124
|
+
omit_if(@@windows, 'group test skipped on MS Windows')
|
125
|
+
@rule1 = File::Find.new(:name => '*.doc', :group => @@logroup.name)
|
126
|
+
assert_equal([File.expand_path(@file4)], @rule1.find)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_group_with_bad_id
|
130
|
+
omit_if(@@windows, 'group test skipped on MS Windows')
|
131
|
+
@rule1 = File::Find.new(:name => '*.doc', :group => 'totallybogus')
|
132
|
+
@rule2 = File::Find.new(:name => '*.doc', :group => 99999999)
|
133
|
+
assert_equal([], @rule1.find)
|
134
|
+
assert_equal([], @rule2.find)
|
135
|
+
end
|
136
|
+
|
103
137
|
def test_inum_basic
|
104
138
|
assert_respond_to(@rule1, :inum)
|
105
139
|
assert_respond_to(@rule1, :inum=)
|
@@ -115,13 +149,14 @@ class TC_File_Find < Test::Unit::TestCase
|
|
115
149
|
def test_name_basic
|
116
150
|
assert_respond_to(@rule1, :name)
|
117
151
|
assert_respond_to(@rule1, :name=)
|
118
|
-
assert_equal('*.
|
152
|
+
assert_equal('*.txt', @rule1.name)
|
119
153
|
end
|
120
154
|
|
121
155
|
def test_pattern_alias
|
122
156
|
assert_respond_to(@rule1, :pattern)
|
123
157
|
assert_respond_to(@rule1, :pattern=)
|
124
|
-
|
158
|
+
assert_true(@rule1.method(:name) == @rule1.method(:pattern))
|
159
|
+
assert_true(@rule1.method(:name=) == @rule1.method(:pattern=))
|
125
160
|
end
|
126
161
|
|
127
162
|
def test_perm_basic
|
@@ -130,16 +165,14 @@ class TC_File_Find < Test::Unit::TestCase
|
|
130
165
|
assert_nil(@rule1.perm)
|
131
166
|
end
|
132
167
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
results = File::Find.new(:name => "test1*", :perm => 664).find
|
168
|
+
def test_perm
|
169
|
+
omit_if(@@windows, 'perm test skipped on MS Windows')
|
170
|
+
File.chmod(0664, @file1)
|
171
|
+
File.chmod(0644, @file2)
|
172
|
+
results = File::Find.new(:name => "test1*", :perm => 664).find
|
139
173
|
|
140
|
-
|
141
|
-
|
142
|
-
end
|
174
|
+
assert_equal(1, results.length)
|
175
|
+
assert_equal('test1.rb', File.basename(results.first))
|
143
176
|
end
|
144
177
|
|
145
178
|
def test_prune_basic
|
@@ -165,6 +198,26 @@ class TC_File_Find < Test::Unit::TestCase
|
|
165
198
|
assert_nil(@rule1.user)
|
166
199
|
end
|
167
200
|
|
201
|
+
def test_user_with_numeric_id
|
202
|
+
omit_if(@@windows, 'user test skipped on MS Windows')
|
203
|
+
@rule1 = File::Find.new(:name => '*.doc', :user => @@loguser.uid)
|
204
|
+
assert_equal([File.expand_path(@file4)], @rule1.find)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_user_with_string
|
208
|
+
omit_if(@@windows, 'user test skipped on MS Windows')
|
209
|
+
@rule1 = File::Find.new(:name => '*.doc', :user => @@loguser.name)
|
210
|
+
assert_equal([File.expand_path(@file4)], @rule1.find)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_user_with_bad_id
|
214
|
+
omit_if(@@windows, 'user test skipped on MS Windows')
|
215
|
+
@rule1 = File::Find.new(:name => '*.doc', :user => 'totallybogus')
|
216
|
+
@rule2 = File::Find.new(:name => '*.doc', :user => 99999999)
|
217
|
+
assert_equal([], @rule1.find)
|
218
|
+
assert_equal([], @rule2.find)
|
219
|
+
end
|
220
|
+
|
168
221
|
def test_previous_basic
|
169
222
|
assert_respond_to(@rule1, :previous)
|
170
223
|
end
|
@@ -177,8 +230,22 @@ class TC_File_Find < Test::Unit::TestCase
|
|
177
230
|
FileUtils.rm_rf(@file1)
|
178
231
|
FileUtils.rm_rf(@file2)
|
179
232
|
FileUtils.rm_rf(@file3)
|
233
|
+
FileUtils.rm_rf(@file4)
|
180
234
|
FileUtils.rm_rf(@dir1)
|
181
235
|
FileUtils.rm_rf(@dir2)
|
182
|
-
FileUtils.rm_rf(@link1) unless
|
236
|
+
FileUtils.rm_rf(@link1) unless @@windows
|
237
|
+
|
238
|
+
@rule1 = nil
|
239
|
+
@rule2 = nil
|
240
|
+
@file1 = nil
|
241
|
+
@file2 = nil
|
242
|
+
@file3 = nil
|
243
|
+
@file4 = nil
|
244
|
+
end
|
245
|
+
|
246
|
+
def self.shutdown
|
247
|
+
@@windows = nil
|
248
|
+
@@loguser = nil unless @@windows
|
249
|
+
@@logroup = nil unless @@windows
|
183
250
|
end
|
184
251
|
end
|
metadata
CHANGED
@@ -1,53 +1,79 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: file-find
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-10-05 00:00:00 -06:00
|
8
|
-
summary: A better way to find files
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/shards
|
13
|
-
rubyforge_project:
|
14
|
-
description: A better way to find files
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.2.2
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sys-admin
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.4.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: test-unit
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.1
|
34
|
+
version:
|
35
|
+
description: A better way to find files
|
36
|
+
email: djberg96@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README
|
43
|
+
- CHANGES
|
44
|
+
- MANIFEST
|
31
45
|
files:
|
32
46
|
- lib/file
|
33
47
|
- lib/file/find.rb
|
34
|
-
- test/
|
48
|
+
- test/test_file_find.rb
|
35
49
|
- README
|
36
50
|
- CHANGES
|
37
51
|
- MANIFEST
|
38
|
-
|
39
|
-
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://www.rubyforge.org/projects/shards
|
54
|
+
post_install_message:
|
40
55
|
rdoc_options: []
|
41
56
|
|
42
|
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
50
71
|
requirements: []
|
51
72
|
|
52
|
-
|
53
|
-
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.2.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: A better way to find files
|
78
|
+
test_files:
|
79
|
+
- test/test_file_find.rb
|