all files in FsSnapshot, but with ignored flag

This commit is contained in:
Johan Holmberg
2016-10-30 18:05:33 +01:00
parent 8a2af873ef
commit 6e16688a1b
2 changed files with 20 additions and 14 deletions

@ -25,12 +25,14 @@ module Cmdtest
class FileInfo
attr_reader :stat, :digest
attr_accessor :ignored
def initialize(relpath, topdir)
@topdir = topdir
@relpath = relpath
@path = File.join(topdir, relpath)
@stat = File.lstat(@path)
@ignored = false
if @stat.file?
md5 = Digest::MD5.new

@ -27,16 +27,17 @@ require "find"
module Cmdtest
class FsSnapshot
def relative_find(dir)
dir_prefix = @dir + "/"
Find.find(dir) do |path|
if path == dir
yield "."
elsif path.index(dir_prefix) != 0
raise "not a prefix: #{dir_prefix}, #{dir}"
def recursive_find(ignore, prefix, dir, &block)
for entry in Dir.entries(dir)
next if entry == "."
next if entry == ".."
path = File.join(dir, entry)
relpath = prefix + entry
if File.directory?(path)
ignore2 = yield ignore, relpath
recursive_find(ignore2, relpath + "/", path, &block)
else
path[0, dir_prefix.length] = ""
yield path
ignore2 = yield ignore, relpath
end
end
end
@ -45,12 +46,14 @@ module Cmdtest
@dir = dir
@ignored_files = ignored_files
@fileinfo_by_path = {}
relative_find(@dir) do |path|
next if path == "."
recursive_find(false, "", @dir) do |ignore, path|
file_info = FileInfo.new(path, @dir)
display_path = file_info.display_path
Find.prune if _ignore_file?(display_path)
ignore2 = ignore || _ignore_file?(display_path)
@fileinfo_by_path[display_path] = file_info
file_info.ignored = ignore2
ignore2
end
end
@ -66,8 +69,9 @@ module Cmdtest
def files
@fileinfo_by_path.keys.sort.select do |path|
stat = @fileinfo_by_path[path].stat
stat.file? || stat.directory?
fileinfo = @fileinfo_by_path[path]
stat = fileinfo.stat
! fileinfo.ignored && (stat.file? || stat.directory?)
end
end