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

View File

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

View File

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