lib/filesystemwatcher.rb
# start watching the specified files/directories

start watching the specified files/directories
start watching the specified files / directories
def start(&block)
    if isStarted? then
      raise RuntimeError, "already started"
    end
    setState(STARTED)
    @firstLoad = true
    @foundFiles = Hash.new()
    @watchThread = Thread.new {
      while !isStopped? do
	if (!@directories.empty?) or (!@files.empty?) then	
	  alreadyExamined = Hash.new()
	  if not @directories.empty? then
	    @directories.each { |dirObj|
	      examineFileList(dirObj.getFiles(), alreadyExamined, &block)
	    }
	  end
	  examineFileList(@files, alreadyExamined, &block) if not @files.empty?
	  if not @firstLoad then
	    if not @foundFiles.empty? then
	      allFoundFiles = @foundFiles.keys()
	      allExaminedFiles = alreadyExamined.keys()
	      intersection = allFoundFiles - allExaminedFiles
	      intersection.each { |fileName|
		block.call(DELETED, fileName)
		@foundFiles.delete(fileName)
	      }	  
	    end
	  else
	    @firstLoad = false
	  end
	end
	sleep(@sleepTime)
      end
    }
    @watchThread.priority = @priority
  end
def start ( & block ) if isStarted? then raise RuntimeError , "already started" end setState ( STARTED ) @firstLoad = true @foundFiles = Hash . new ( ) @watchThread = Thread . new { while ! isStopped? do if ( ! @directories . empty? ) or ( ! @files . empty? ) then alreadyExamined = Hash . new ( ) if not @directories . empty? then @directories . each { | dirObj | examineFileList ( dirObj . getFiles ( ) , alreadyExamined , & block ) } end examineFileList ( @files , alreadyExamined , & block ) if not @files . empty? if not @firstLoad then if not @foundFiles . empty? then allFoundFiles = @foundFiles . keys ( ) allExaminedFiles = alreadyExamined . keys ( ) intersection = allFoundFiles - allExaminedFiles intersection . each { | fileName | block . call ( DELETED , fileName ) @foundFiles . delete ( fileName ) } end else @firstLoad = false end end sleep ( @sleepTime ) end } @watchThread . priority = @priority end
start watching the specified files/directories
start watching the specified files / directories
# we watch in a new thread
 # we will be stopped if someone calls stop or if someone set a stopWhen that becomes true
 # this will hold the list of the files we looked at this iteration
 # allows us to not look at the same file again and also to compare
 # with the foundFile list to see if something was deleted
 # check the files in each watched directory
 # now examine any files the user wants to specifically watch
 # see if we have to delete files from our found list
 # now diff the found files and the examined files to see if
 # something has been deleted
 # callback
 # remove deleted file from the foundFiles list
 # go to sleep
 # set the watch thread priority

block
<not_specific>