file-find 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGES +7 -0
  2. data/README +17 -12
  3. data/lib/file/find.rb +26 -5
  4. data/test/tc_find.rb +29 -10
  5. metadata +3 -3
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.1 - 4-Oct-2007
2
+ * Added the File::Find#previous method, which lets you see the previous
3
+ match, if any.
4
+ * Path name bug fix for MS Windows.
5
+ * Test suite bug fixes for MS Windows (perm test now skipped).
6
+ * Inaccessible directories are now skipped instead of raising an error.
7
+
1
8
  == 0.2.0 - 26-Apr-2007
2
9
  * Fixed a bug where it was not traversing subdirectories.
3
10
  * Added support for the perm and prune options.
data/README CHANGED
@@ -4,7 +4,7 @@ library. It is modeled on a typical 'find' command found on most Unix systems.
4
4
 
5
5
  = Synopsis
6
6
  rule = File::Find.new(
7
- :name => "*.rb",
7
+ :pattern => "*.rb",
8
8
  :follow => false,
9
9
  :path => ['/usr/local/lib', '/opt/local/lib']
10
10
  )
@@ -14,8 +14,8 @@ library. It is modeled on a typical 'find' command found on most Unix systems.
14
14
  }
15
15
 
16
16
  = Installation
17
- rake test (optional)
18
- rake install (non-gem) or rake install_gem (gem)
17
+ * rake test (optional)
18
+ * rake install (non-gem) -OR- rake install_gem (gem)
19
19
 
20
20
  = Rationale
21
21
  The current find module in the standard library is inadequate. It is, quite
@@ -31,11 +31,11 @@ few options, hasn't been updated in over six years and isn't packaged properly.
31
31
  * ctime
32
32
  * follow
33
33
  * ftype
34
- * inum
34
+ * inum (except Windows)
35
35
  * group
36
- * name
36
+ * name (or 'pattern')
37
37
  * path
38
- * perm
38
+ * perm (except Windows)
39
39
  * prune
40
40
  * size
41
41
  * user
@@ -52,17 +52,17 @@ Some specific things I plan on adding:
52
52
  * exec
53
53
  * links
54
54
 
55
- = Options that I won't support
55
+ = Options I won't support
56
56
  Generally speaking, anything that would require mucking around with C code
57
57
  or is just too difficult to implement in a cross platform manner will not be
58
58
  supported. These include the following options:
59
59
 
60
- * acl/xattr - Way to difficult to implement in a cross platform manner, and a
61
- rarely used option to boot.
60
+ * acl/xattr - Way too difficult to implement in a cross platform manner, and
61
+ a rarely used option to boot.
62
62
 
63
63
  * cpio/ncpio - You can shell out on your own if you want, but I'm not going to
64
- do it for you. The same goes for any similar options that your particular
65
- platform may support.
64
+ do it for you. The same goes for any similar options for 3rd party apps that
65
+ your particular platform may support.
66
66
 
67
67
  * ls/print - You can print file names as you see fit on your own. This isn't
68
68
  a shell command replacement.
@@ -71,8 +71,13 @@ supported. These include the following options:
71
71
 
72
72
  = Options I may or may not support
73
73
 
74
- * local/mount/xdev - This will probably not be added until I'm satisified with
74
+ * local/mount/xdev - This will probably not be added until I'm satisfied with
75
75
  the sys-filesystem package.
76
+
77
+ = Known Issues
78
+ The 'perm' option does not work on MS Windows, even for its limited subset of
79
+ permissions, i.e. 664 and 666. This is arguably a bug in Ruby's
80
+ File::Stat.mode method on MS Windows.
76
81
 
77
82
  = Bugs
78
83
  None that I'm aware of. Please log any bug reports on the project page at
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  class File::Find
4
4
  # The version of this package
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
 
7
7
  # :stopdoc:
8
8
  VALID_OPTIONS = %w/
@@ -13,6 +13,7 @@ class File::Find
13
13
  inum
14
14
  group
15
15
  name
16
+ pattern
16
17
  path
17
18
  perm
18
19
  prune
@@ -90,7 +91,12 @@ class File::Find
90
91
  #
91
92
  attr_accessor :user
92
93
 
94
+ # The file that matched previously in the current search.
95
+ #
96
+ attr_reader :previous
97
+
93
98
  alias pattern name
99
+ alias pattern= name=
94
100
 
95
101
  # Creates and returns a new File::Find object. The options set for this
96
102
  # object serve as the rules for determining what files the File::Find#find
@@ -112,6 +118,8 @@ class File::Find
112
118
 
113
119
  validate_and_set_options(options) unless options.empty?
114
120
 
121
+ @previous = nil
122
+
115
123
  @path ||= Dir.pwd
116
124
  @name ||= '*'
117
125
  end
@@ -130,8 +138,8 @@ class File::Find
130
138
  prune_regex = nil
131
139
  end
132
140
 
133
- catch(:loop) do
134
- paths.each{ |path|
141
+ paths.each{ |path|
142
+ begin
135
143
  Dir.foreach(path){ |file|
136
144
  next if file == '.'
137
145
  next if file == '..'
@@ -168,6 +176,11 @@ class File::Find
168
176
  end
169
177
  end
170
178
 
179
+ # Dir[] doesn't like backslashes
180
+ if File::ALT_SEPARATOR
181
+ file.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
182
+ end
183
+
171
184
  next unless Dir[glob].include?(file)
172
185
 
173
186
  if @atime
@@ -196,6 +209,10 @@ class File::Find
196
209
  end
197
210
  end
198
211
 
212
+ # This currently doesn't work on MS Windows, even in limited
213
+ # fashion for 0666 and 0664, because File.stat.mode doesn't
214
+ # return the proper value.
215
+ #
199
216
  if @perm
200
217
  next unless sprintf("%o", stat_info.mode & 07777) == @perm.to_s
201
218
  end
@@ -228,9 +245,13 @@ class File::Find
228
245
  else
229
246
  results << file
230
247
  end
248
+
249
+ @previous = file unless @previous == file
231
250
  }
232
- }
233
- end
251
+ rescue Errno::EACCES
252
+ next # Skip inaccessible directories
253
+ end
254
+ }
234
255
 
235
256
  block_given? ? nil : results
236
257
  end
@@ -9,18 +9,23 @@ require 'fileutils'
9
9
  require 'file/find'
10
10
 
11
11
  class TC_File_Find < Test::Unit::TestCase
12
+ WINDOWS = RUBY_PLATFORM.match('mswin') ? true : false
13
+
12
14
  def setup
13
15
  @file1 = 'test1.rb'
14
16
  @file2 = 'test1.txt'
15
17
  @file3 = 'foo.txt'
16
- @link1 = 'link1'
17
18
  @dir1 = 'dir1'
18
19
  @dir2 = 'dir2'
19
20
 
20
21
  File.open(@file1, 'w'){}
21
22
  File.open(@file2, 'w'){}
22
23
  File.open(@file3, 'w'){}
23
- File.symlink(@file1, @link1)
24
+
25
+ unless WINDOWS
26
+ @link1 = 'link1'
27
+ File.symlink(@file1, @link1)
28
+ end
24
29
 
25
30
  Dir.mkdir(@dir1) unless File.exists?(@dir1)
26
31
  Dir.mkdir(@dir2) unless File.exists?(@dir2)
@@ -32,7 +37,7 @@ class TC_File_Find < Test::Unit::TestCase
32
37
  end
33
38
 
34
39
  def test_version
35
- assert_equal('0.2.0', File::Find::VERSION)
40
+ assert_equal('0.2.1', File::Find::VERSION)
36
41
  end
37
42
 
38
43
  def test_path
@@ -113,18 +118,28 @@ class TC_File_Find < Test::Unit::TestCase
113
118
  assert_equal('*.rb', @rule1.name)
114
119
  end
115
120
 
121
+ def test_pattern_alias
122
+ assert_respond_to(@rule1, :pattern)
123
+ assert_respond_to(@rule1, :pattern=)
124
+ assert_equal('*.rb', @rule1.pattern)
125
+ end
126
+
116
127
  def test_perm_basic
117
128
  assert_respond_to(@rule1, :perm)
118
129
  assert_respond_to(@rule1, :perm=)
119
130
  assert_nil(@rule1.perm)
120
131
  end
121
132
 
122
- def test_perm
123
- File.chmod(0666, @file1)
124
- File.chmod(0644, @file2)
125
- results = File::Find.new(:name => "test1*", :perm => 666).find
126
- assert_equal(true, results.length == 1)
127
- assert_equal('test1.rb', File.basename(results.first))
133
+ # Skip on MS Windows for now
134
+ unless WINDOWS
135
+ def test_perm
136
+ File.chmod(0664, @file1)
137
+ File.chmod(0644, @file2)
138
+ results = File::Find.new(:name => "test1*", :perm => 664).find
139
+
140
+ assert_equal(1, results.length)
141
+ assert_equal('test1.rb', File.basename(results.first))
142
+ end
128
143
  end
129
144
 
130
145
  def test_prune_basic
@@ -150,6 +165,10 @@ class TC_File_Find < Test::Unit::TestCase
150
165
  assert_nil(@rule1.user)
151
166
  end
152
167
 
168
+ def test_previous_basic
169
+ assert_respond_to(@rule1, :previous)
170
+ end
171
+
153
172
  def test_expected_errors
154
173
  assert_raises(Errno::ENOENT){ File::Find.new(:path => '/bogus/dir').find }
155
174
  end
@@ -158,8 +177,8 @@ class TC_File_Find < Test::Unit::TestCase
158
177
  FileUtils.rm_rf(@file1)
159
178
  FileUtils.rm_rf(@file2)
160
179
  FileUtils.rm_rf(@file3)
161
- FileUtils.rm_rf(@link1)
162
180
  FileUtils.rm_rf(@dir1)
163
181
  FileUtils.rm_rf(@dir2)
182
+ FileUtils.rm_rf(@link1) unless WINDOWS
164
183
  end
165
184
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: file-find
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-04-26 00:00:00 -06:00
6
+ version: 0.2.1
7
+ date: 2007-10-05 00:00:00 -06:00
8
8
  summary: A better way to find files
9
9
  require_paths:
10
10
  - lib