file-find 0.3.0 → 0.3.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.
- data/CHANGES +7 -0
- data/README +5 -0
- data/lib/file/find.rb +51 -22
- data/test/test_file_find.rb +23 -4
- metadata +7 -7
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.3.1 - 9-Jan-2008
|
2
|
+
* Now defaults to using Etc instead of Sys::Admin for implementations
|
3
|
+
that don't support building C extensions, e.g. JRuby.
|
4
|
+
* Updated the test suite to work with JRuby.
|
5
|
+
* Minor optimizations for symbolic perms and atime/ctime/mtime checks.
|
6
|
+
Thanks go in part to Ryan Davis' flay library.
|
7
|
+
|
1
8
|
== 0.3.0 - 30-Dec-2008
|
2
9
|
* Added support for FileTest operations. All options passed to the constructor
|
3
10
|
that end with '?' are now validated and treated as FileTest operations.
|
data/README
CHANGED
@@ -87,6 +87,11 @@ The 'user' and 'group' options are not currently supported on MS Windows.
|
|
87
87
|
This can be supported, but will require changes in the win32-file and
|
88
88
|
win32-file-stat libraries (which would then become dependencies).
|
89
89
|
|
90
|
+
There are 3 test failures with JRuby, all related to the 'perm' option. I
|
91
|
+
have not been able to reduce them to a simple test case and discern the
|
92
|
+
exact cause of the failures, though I suspect a bug in the JRuby
|
93
|
+
implementation of File.chmod.
|
94
|
+
|
90
95
|
= Bugs
|
91
96
|
None that I'm aware of. Please log any bug reports on the project page at
|
92
97
|
http://www.rubyforge.org/projects/shards.
|
data/lib/file/find.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'rbconfig'
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
# For alternate implementations of Ruby, such as JRuby, that cannot
|
5
|
+
# build C extensions fall back to the Etc module.
|
6
|
+
begin
|
7
|
+
require 'sys/admin'
|
8
|
+
rescue LoadError
|
9
|
+
require 'etc'
|
10
|
+
end
|
6
11
|
|
7
12
|
class File::Find
|
8
13
|
# The version of this library
|
9
|
-
VERSION = '0.3.
|
14
|
+
VERSION = '0.3.1'
|
10
15
|
|
11
16
|
# :stopdoc:
|
12
17
|
VALID_OPTIONS = %w/
|
@@ -226,7 +231,7 @@ class File::Find
|
|
226
231
|
next
|
227
232
|
rescue Errno::ELOOP
|
228
233
|
stat_method = :lstat # Handle recursive symlinks
|
229
|
-
retry
|
234
|
+
retry if stat_method.to_s != 'lstat'
|
230
235
|
end
|
231
236
|
|
232
237
|
glob = File.join(File.dirname(file), @name)
|
@@ -288,22 +293,23 @@ class File::Find
|
|
288
293
|
next unless file_test
|
289
294
|
end
|
290
295
|
|
291
|
-
if @atime
|
296
|
+
if @atime || @ctime || @mtime
|
292
297
|
date1 = Date.parse(Time.now.to_s)
|
293
|
-
date2 = Date.parse(stat_info.atime.to_s)
|
294
|
-
next unless (date1 - date2).numerator == @atime
|
295
|
-
end
|
296
298
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
end
|
299
|
+
if @atime
|
300
|
+
date2 = Date.parse(stat_info.atime.to_s)
|
301
|
+
next unless (date1 - date2).numerator == @atime
|
302
|
+
end
|
302
303
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
304
|
+
if @ctime
|
305
|
+
date2 = Date.parse(stat_info.ctime.to_s)
|
306
|
+
next unless (date1 - date2).numerator == @ctime
|
307
|
+
end
|
308
|
+
|
309
|
+
if @mtime
|
310
|
+
date2 = Date.parse(stat_info.mtime.to_s)
|
311
|
+
next unless (date1 - date2).numerator == @mtime
|
312
|
+
end
|
307
313
|
end
|
308
314
|
|
309
315
|
if @ftype
|
@@ -312,13 +318,13 @@ class File::Find
|
|
312
318
|
|
313
319
|
if @group
|
314
320
|
if @group.is_a?(String)
|
315
|
-
next unless
|
321
|
+
next unless get_group(stat_info.gid).name == @group
|
316
322
|
else
|
317
323
|
next unless stat_info.gid == @group
|
318
324
|
end
|
319
325
|
end
|
320
326
|
|
321
|
-
unless CONFIG['host_os'] =~ /windows|mswin/i
|
327
|
+
unless Config::CONFIG['host_os'] =~ /windows|mswin/i
|
322
328
|
if @inum
|
323
329
|
next unless stat_info.ino == @inum
|
324
330
|
end
|
@@ -330,7 +336,8 @@ class File::Find
|
|
330
336
|
#
|
331
337
|
if @perm
|
332
338
|
if @perm.is_a?(String)
|
333
|
-
|
339
|
+
octal_perm = sym2oct(@perm)
|
340
|
+
next unless stat_info.mode & octal_perm == octal_perm
|
334
341
|
else
|
335
342
|
next unless sprintf("%o", stat_info.mode & 07777) == @perm.to_s
|
336
343
|
end
|
@@ -357,7 +364,7 @@ class File::Find
|
|
357
364
|
|
358
365
|
if @user
|
359
366
|
if @user.is_a?(String)
|
360
|
-
next unless
|
367
|
+
next unless get_user(stat_info.uid).name == @user
|
361
368
|
else
|
362
369
|
next unless stat_info.uid == @user
|
363
370
|
end
|
@@ -442,4 +449,26 @@ class File::Find
|
|
442
449
|
|
443
450
|
perm
|
444
451
|
end
|
452
|
+
|
453
|
+
# Returns the group object based on the group id. Implemented for the
|
454
|
+
# sake of platforms that cannot build extensions, such as JRuby.
|
455
|
+
#
|
456
|
+
def get_group(gid)
|
457
|
+
if defined? Sys::Admin
|
458
|
+
Sys::Admin.get_group(gid)
|
459
|
+
else
|
460
|
+
Etc.getgrgid(gid)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
# Returns the user object based on the group id. Implemented for the
|
465
|
+
# sake of platforms that cannot build extensions, such as JRuby.
|
466
|
+
#
|
467
|
+
def get_user(uid)
|
468
|
+
if defined? Sys::Admin
|
469
|
+
Sys::Admin.get_user(uid)
|
470
|
+
else
|
471
|
+
Etc.getpwuid(uid)
|
472
|
+
end
|
473
|
+
end
|
445
474
|
end
|
data/test/test_file_find.rb
CHANGED
@@ -11,16 +11,32 @@ require 'test/unit'
|
|
11
11
|
require 'fileutils'
|
12
12
|
require 'file/find'
|
13
13
|
require 'rbconfig'
|
14
|
-
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'sys/admin'
|
17
|
+
rescue LoadError
|
18
|
+
require 'etc'
|
19
|
+
end
|
20
|
+
|
15
21
|
include Config
|
16
22
|
include FileUtils
|
17
23
|
|
18
24
|
class TC_File_Find < Test::Unit::TestCase
|
19
25
|
def self.startup
|
20
26
|
Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
|
27
|
+
|
21
28
|
@@windows = CONFIG['host_os'] =~ /windows|mswin/i
|
22
|
-
@@
|
23
|
-
|
29
|
+
@@jruby = RUBY_PLATFORM.match('java')
|
30
|
+
|
31
|
+
unless @@windows
|
32
|
+
if @@jruby
|
33
|
+
@@loguser = Etc.getpwnam(Etc.getlogin)
|
34
|
+
@@logroup = Etc.getgrgid(@@loguser.gid)
|
35
|
+
else
|
36
|
+
@@loguser = Sys::Admin.get_user(Sys::Admin.get_login)
|
37
|
+
@@logroup = Sys::Admin.get_group(@@loguser.gid)
|
38
|
+
end
|
39
|
+
end
|
24
40
|
end
|
25
41
|
|
26
42
|
def setup
|
@@ -52,7 +68,7 @@ class TC_File_Find < Test::Unit::TestCase
|
|
52
68
|
end
|
53
69
|
|
54
70
|
def test_version
|
55
|
-
assert_equal('0.3.
|
71
|
+
assert_equal('0.3.1', File::Find::VERSION)
|
56
72
|
end
|
57
73
|
|
58
74
|
def test_path
|
@@ -118,6 +134,8 @@ class TC_File_Find < Test::Unit::TestCase
|
|
118
134
|
end
|
119
135
|
|
120
136
|
def test_filetest
|
137
|
+
omit_if(@@windows && @@jruby, "Skipping file test on JRuby/Windows")
|
138
|
+
|
121
139
|
rule = File::Find.new(:name => "*.doc", :writable? => true)
|
122
140
|
File.chmod(0644, @file4)
|
123
141
|
|
@@ -406,6 +424,7 @@ class TC_File_Find < Test::Unit::TestCase
|
|
406
424
|
|
407
425
|
def self.shutdown
|
408
426
|
@@windows = nil
|
427
|
+
@@jruby = nil
|
409
428
|
@@loguser = nil unless @@windows
|
410
429
|
@@logroup = nil unless @@windows
|
411
430
|
end
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Berger
|
@@ -9,28 +9,28 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: test-unit
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.0.2
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: sys-admin
|
27
27
|
type: :runtime
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.4.4
|
34
34
|
version:
|
35
35
|
description: A better way to find files
|
36
36
|
email: djberg96@gmail.com
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements: []
|
72
72
|
|
73
73
|
rubyforge_project: shards
|
74
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.3.1
|
75
75
|
signing_key:
|
76
76
|
specification_version: 2
|
77
77
|
summary: A better way to find files
|