Class: PhusionPassenger::Utils::FileSystemWatcher::DirInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/phusion_passenger/utils/file_system_watcher.rb

Constant Summary collapse

DOT =
"."
DOTDOT =
".."

Instance Method Summary collapse

Constructor Details

#initialize(filename, stat) ⇒ DirInfo

Returns a new instance of DirInfo.



123
124
125
126
127
128
129
130
131
132
# File 'lib/phusion_passenger/utils/file_system_watcher.rb', line 123

def initialize(filename, stat)
	@filename = filename
	@stat = stat
	@subfiles = {}
	Dir.foreach(filename) do |entry|
		next if entry == DOT || entry == DOTDOT
		subfilename = "#{filename}/#{entry}"
		@subfiles[entry] = FileInfo.new(subfilename, File.stat(subfilename))
	end
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/phusion_passenger/utils/file_system_watcher.rb', line 134

def changed?
	new_stat = File.stat(@filename)
	if @stat.ino != new_stat.ino || !new_stat.directory? || @stat.mtime != new_stat.mtime
		return true
	end
	
	count = 0
	Dir.foreach(@filename) do |entry|
		next if entry == DOT || entry == DOTDOT
		subfilename = "#{@filename}/#{entry}"
	
		file_info = @subfiles[entry]
		if !file_info || file_info.changed?(false)
			return true
		else
			count += 1
		end
	end
	
	return count != @subfiles.size
rescue Errno::EACCES, Errno::ENOENT
	return true
end