file-find 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/README +10 -11
- data/lib/file/find.rb +19 -5
- data/test/test_file_find.rb +22 -8
- metadata +4 -4
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.2.3 - 25-Nov-2008
|
2
|
+
* Added mtime support. My previous concerns, which I believe stemmed from
|
3
|
+
the find(2) man page on Solaris 10 with regards to atime checks modifying
|
4
|
+
the mtime, appear have been unfounded.
|
5
|
+
|
1
6
|
== 0.2.2 - 19-Nov-2008
|
2
7
|
* The :user and :group options now accept a name or a numeric id. Thanks go
|
3
8
|
to Bill Kleb for the suggestion.
|
data/README
CHANGED
@@ -19,11 +19,11 @@ library. It is modeled on a typical 'find' command found on most Unix systems.
|
|
19
19
|
|
20
20
|
= Rationale
|
21
21
|
The current find module in the standard library is inadequate. It is, quite
|
22
|
-
frankly, not much more than a plain Dir.glob call. This
|
22
|
+
frankly, not much more than a plain Dir.glob call. This library provides an
|
23
23
|
interface based on options typically available on your command line 'find'
|
24
24
|
command, thus allowing you much greater control over how you find your files.
|
25
25
|
|
26
|
-
I am aware of the find2
|
26
|
+
I am aware of the find2 library by Motoyuki Kasahara, but it supports very
|
27
27
|
few options, hasn't been updated in over six years and isn't packaged properly.
|
28
28
|
|
29
29
|
= Options
|
@@ -32,13 +32,14 @@ few options, hasn't been updated in over six years and isn't packaged properly.
|
|
32
32
|
* follow
|
33
33
|
* ftype
|
34
34
|
* inum (except Windows)
|
35
|
-
* group
|
35
|
+
* group (name or id)
|
36
|
+
* mtime
|
36
37
|
* name (or 'pattern')
|
37
38
|
* path
|
38
39
|
* perm (except Windows)
|
39
40
|
* prune
|
40
41
|
* size
|
41
|
-
* user
|
42
|
+
* user (name or id)
|
42
43
|
|
43
44
|
See the RDoc documentation for more details about these options.
|
44
45
|
|
@@ -60,21 +61,18 @@ or is just too difficult to implement in a cross platform manner will not be
|
|
60
61
|
supported. These include the following options:
|
61
62
|
|
62
63
|
* acl/xattr - Way too difficult to implement in a cross platform manner, and
|
63
|
-
a rarely used option
|
64
|
+
a rarely used option in practice.
|
64
65
|
|
65
|
-
* cpio/ncpio -
|
66
|
-
do it for you. The same goes for any similar options for 3rd party apps that
|
67
|
-
your particular platform may support.
|
66
|
+
* cpio/ncpio - I will not shell out to this or any other 3rd party application.
|
68
67
|
|
69
|
-
* ls/print -
|
70
|
-
a shell command replacement.
|
68
|
+
* ls/print - Use Ruby's builtin printing methods to print as you see fit.
|
71
69
|
|
72
70
|
* ok - This is not interactive software.
|
73
71
|
|
74
72
|
= Options I may or may not support
|
75
73
|
|
76
74
|
* local/mount/xdev - This will probably not be added until I'm satisfied with
|
77
|
-
the sys-filesystem
|
75
|
+
the sys-filesystem library. As of sys-filesystem 0.1.x, I'm not.
|
78
76
|
|
79
77
|
= Known Issues
|
80
78
|
The 'perm' option does not work on MS Windows, even for its limited subset of
|
@@ -92,6 +90,7 @@ http://www.rubyforge.org/projects/shards.
|
|
92
90
|
= Acknowledgements
|
93
91
|
* Richard Clamp's File::Find::Rule Perl module for additional ideas and
|
94
92
|
inspiration.
|
93
|
+
* Bill Kleb for ideas regarding name, group and perm enhancements.
|
95
94
|
|
96
95
|
= License
|
97
96
|
Ruby's
|
data/lib/file/find.rb
CHANGED
@@ -6,7 +6,7 @@ include Sys
|
|
6
6
|
|
7
7
|
class File::Find
|
8
8
|
# The version of this library
|
9
|
-
VERSION = '0.2.
|
9
|
+
VERSION = '0.2.3'
|
10
10
|
|
11
11
|
# :stopdoc:
|
12
12
|
VALID_OPTIONS = %w/
|
@@ -16,6 +16,7 @@ class File::Find
|
|
16
16
|
ftype
|
17
17
|
inum
|
18
18
|
group
|
19
|
+
mtime
|
19
20
|
name
|
20
21
|
pattern
|
21
22
|
path
|
@@ -38,8 +39,7 @@ class File::Find
|
|
38
39
|
|
39
40
|
# Limits searches by file access time, where the value you supply is the
|
40
41
|
# number of days back from the time that the File::Find#find method was
|
41
|
-
# called.
|
42
|
-
# times.
|
42
|
+
# called.
|
43
43
|
#
|
44
44
|
attr_accessor :atime
|
45
45
|
|
@@ -56,8 +56,9 @@ class File::Find
|
|
56
56
|
#
|
57
57
|
attr_accessor :group
|
58
58
|
|
59
|
-
# Controls the behavior of how symlinks are followed. If set to true
|
60
|
-
# follows the file pointed to. If false, it considers the
|
59
|
+
# Controls the behavior of how symlinks are followed. If set to true (the
|
60
|
+
# default), then follows the file pointed to. If false, it considers the
|
61
|
+
# symlink itself.
|
61
62
|
#
|
62
63
|
attr_accessor :follow
|
63
64
|
|
@@ -71,6 +72,12 @@ class File::Find
|
|
71
72
|
#
|
72
73
|
attr_accessor :inum
|
73
74
|
|
75
|
+
# Limits searches by file modification time, where the value you supply is
|
76
|
+
# the number of days back from the time that the File::Find#find method was
|
77
|
+
# called.
|
78
|
+
#
|
79
|
+
attr_accessor :mtime
|
80
|
+
|
74
81
|
# The name pattern used to limit file searches. The patterns that are legal
|
75
82
|
# for Dir.glob are legal here. The default is '*', i.e. everything.
|
76
83
|
#
|
@@ -131,6 +138,7 @@ class File::Find
|
|
131
138
|
@group = nil
|
132
139
|
@follow = true
|
133
140
|
@inum = nil
|
141
|
+
@mtime = nil
|
134
142
|
@perm = nil
|
135
143
|
@prune = nil
|
136
144
|
@size = nil
|
@@ -228,6 +236,12 @@ class File::Find
|
|
228
236
|
next unless (date1 - date2).numerator == @ctime
|
229
237
|
end
|
230
238
|
|
239
|
+
if @mtime
|
240
|
+
date1 = Date.parse(Time.now.to_s)
|
241
|
+
date2 = Date.parse(stat_info.mtime.to_s)
|
242
|
+
next unless (date1 - date2).numerator == @mtime
|
243
|
+
end
|
244
|
+
|
231
245
|
if @ftype
|
232
246
|
next unless File.ftype(file) == @ftype
|
233
247
|
end
|
data/test/test_file_find.rb
CHANGED
@@ -51,7 +51,7 @@ class TC_File_Find < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_version
|
54
|
-
assert_equal('0.2.
|
54
|
+
assert_equal('0.2.3', File::Find::VERSION)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_path
|
@@ -76,8 +76,8 @@ class TC_File_Find < Test::Unit::TestCase
|
|
76
76
|
rule1 = File::Find.new(:name => "*.rb", :atime => 0)
|
77
77
|
rule2 = File::Find.new(:name => "*.rb", :atime => 1)
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
assert_false(rule1.find.empty?)
|
80
|
+
assert_true(rule2.find.empty?)
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_ctime_basic
|
@@ -90,8 +90,22 @@ class TC_File_Find < Test::Unit::TestCase
|
|
90
90
|
rule1 = File::Find.new(:name => "*.rb", :ctime => 0)
|
91
91
|
rule2 = File::Find.new(:name => "*.rb", :ctime => 1)
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
assert_false(rule1.find.empty?)
|
94
|
+
assert_true(rule2.find.empty?)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_mtime
|
98
|
+
rule1 = File::Find.new(:name => "*.rb", :mtime => 0)
|
99
|
+
rule2 = File::Find.new(:name => "*.rb", :mtime => 1)
|
100
|
+
|
101
|
+
assert_false(rule1.find.empty?)
|
102
|
+
assert_true(rule2.find.empty?)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_mtime_basic
|
106
|
+
assert_respond_to(@rule1, :mtime)
|
107
|
+
assert_respond_to(@rule1, :mtime=)
|
108
|
+
assert_nil(@rule1.mtime)
|
95
109
|
end
|
96
110
|
|
97
111
|
def test_ftype_basic
|
@@ -104,8 +118,8 @@ class TC_File_Find < Test::Unit::TestCase
|
|
104
118
|
rule1 = File::Find.new(:name => "*.rb", :ftype => "file")
|
105
119
|
rule2 = File::Find.new(:name => "*.rb", :ftype => "characterSpecial")
|
106
120
|
|
107
|
-
|
108
|
-
|
121
|
+
assert_false(rule1.find.empty?)
|
122
|
+
assert_true(rule2.find.empty?)
|
109
123
|
end
|
110
124
|
|
111
125
|
def test_group_basic
|
@@ -143,7 +157,7 @@ class TC_File_Find < Test::Unit::TestCase
|
|
143
157
|
def test_follow_basic
|
144
158
|
assert_respond_to(@rule1, :follow)
|
145
159
|
assert_respond_to(@rule1, :follow=)
|
146
|
-
|
160
|
+
assert_true(@rule1.follow)
|
147
161
|
end
|
148
162
|
|
149
163
|
def test_name_basic
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-find
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Berger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -70,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version:
|
71
71
|
requirements: []
|
72
72
|
|
73
|
-
rubyforge_project:
|
74
|
-
rubygems_version: 1.
|
73
|
+
rubyforge_project: shards
|
74
|
+
rubygems_version: 1.3.1
|
75
75
|
signing_key:
|
76
76
|
specification_version: 2
|
77
77
|
summary: A better way to find files
|