lib/file/find.rb in file-find-0.2.0 vs lib/file/find.rb in file-find-0.2.1

- old
+ new

@@ -1,20 +1,21 @@ require 'date' class File::Find # The version of this package - VERSION = '0.2.0' + VERSION = '0.2.1' # :stopdoc: VALID_OPTIONS = %w/ atime ctime follow ftype inum group name + pattern path perm prune size user @@ -88,11 +89,16 @@ # Limits searches to files that belong to a specific user ID. # attr_accessor :user + # The file that matched previously in the current search. + # + attr_reader :previous + alias pattern name + alias pattern= name= # Creates and returns a new File::Find object. The options set for this # object serve as the rules for determining what files the File::Find#find # method will search for. # @@ -110,10 +116,12 @@ @size = nil @user = nil validate_and_set_options(options) unless options.empty? + @previous = nil + @path ||= Dir.pwd @name ||= '*' end # Executes the find based on the rules you set for the File::Find object. @@ -128,12 +136,12 @@ prune_regex = Regexp.new(@prune) else prune_regex = nil end - catch(:loop) do - paths.each{ |path| + paths.each{ |path| + begin Dir.foreach(path){ |file| next if file == '.' next if file == '..' if prune_regex @@ -166,10 +174,15 @@ unless paths.include?(file) paths << file end end + # Dir[] doesn't like backslashes + if File::ALT_SEPARATOR + file.tr!(File::ALT_SEPARATOR, File::SEPARATOR) + end + next unless Dir[glob].include?(file) if @atime date1 = Date.parse(Time.now.to_s) date2 = Date.parse(stat_info.atime.to_s) @@ -194,10 +207,14 @@ if @inum next unless stat_info.ino == @inum end end + # This currently doesn't work on MS Windows, even in limited + # fashion for 0666 and 0664, because File.stat.mode doesn't + # return the proper value. + # if @perm next unless sprintf("%o", stat_info.mode & 07777) == @perm.to_s end # Allow plain numbers, or strings for comparison operators. @@ -226,12 +243,16 @@ if block_given? yield file else results << file end + + @previous = file unless @previous == file } - } - end + rescue Errno::EACCES + next # Skip inaccessible directories + end + } block_given? ? nil : results end private