lib/filesystemwatcher.rb
# loops over the file list check for new or modified files

loops over the file list check for new or modified files
loops over the file list check for new or modified files
def examineFileList(fileList, alreadyExamined, &block)
    fileList.each { |fileName|
      fullFileName = File.expand_path(fileName)
      if not alreadyExamined.has_key?(fullFileName) then
	if File.readable?(fullFileName) then
	  alreadyExamined[fullFileName] = true
	  modTime, size = File.mtime(fullFileName), File.size(fullFileName)
	  if @firstLoad then
	    @foundFiles[fullFileName] = FSWatcher::FoundFile.new(fullFileName, modTime, size, false, @useMD5)
	  else
	    foundFile = @foundFiles[fullFileName]
	    if foundFile then
	      if foundFile.isNew? then
		if size == foundFile.size then		  
		  block.call(CREATED, fullFileName)
		  foundFile.updateModTime(modTime)
		  foundFile.genMD5() if @useMD5
		else
		  foundFile.updateSize(size)
		end
	      elsif modTime > foundFile.modTime then
		willYield = true
		if @useMD5 then
		  filesMD5 = FSWatcher.genFileMD5(fullFileName)
		  if filesMD5 && foundFile.md5 then
		    if filesMD5.to_s == foundFile.md5.to_s then
		      willYield = false
		    end
		  end
		  foundFile.setMD5(filesMD5) if willYield
		end
		block.call(MODIFIED, fullFileName) if willYield		
		foundFile.updateModTime(modTime)
	      end
	    else	      
	      @foundFiles[fullFileName] = FSWatcher::FoundFile.new(fullFileName, modTime, size)
	    end
	  end
	end
      end
    }
  end
def examineFileList ( fileList , alreadyExamined , & block ) fileList . each { | fileName | fullFileName = File . expand_path ( fileName ) if not alreadyExamined . has_key? ( fullFileName ) then if File . readable? ( fullFileName ) then alreadyExamined [ fullFileName ] = true modTime , size = File . mtime ( fullFileName ) , File . size ( fullFileName ) if @firstLoad then @foundFiles [ fullFileName ] = FSWatcher :: FoundFile . new ( fullFileName , modTime , size , false , @useMD5 ) else foundFile = @foundFiles [ fullFileName ] if foundFile then if foundFile . isNew? then if size == foundFile . size then block . call ( CREATED , fullFileName ) foundFile . updateModTime ( modTime ) foundFile . genMD5 ( ) if @useMD5 else foundFile . updateSize ( size ) end elsif modTime > foundFile . modTime then willYield = true if @useMD5 then filesMD5 = FSWatcher . genFileMD5 ( fullFileName ) if filesMD5 && foundFile . md5 then if filesMD5 . to_s == foundFile . md5 . to_s then willYield = false end end foundFile . setMD5 ( filesMD5 ) if willYield end block . call ( MODIFIED , fullFileName ) if willYield foundFile . updateModTime ( modTime ) end else @foundFiles [ fullFileName ] = FSWatcher :: FoundFile . new ( fullFileName , modTime , size ) end end end end } end
loops over the file list check for new or modified files
loops over the file list check for new or modified files
# expand the file name to the fully qual path
 # dont examine the same file 2 times
 # we cant do much if the file isnt readable anyway
 # set that we have seen this file
 # get the file info
 # on the first iteration just load all of the files into the foundList
 # see if we have found this file already
 # if a file is marked as new, we still need to make sure it isnt still
 # being written to. we do this by checking the file sizes.
 # if the file size is the same then it is probably done being written to
 # unless the writer is really slow
 # callback
 # mark this file as a changed file now
 # generate the md5 for the file since we know it is done
 # being written to
 # just update the size so we can check again at the next iteration
 # if the mod times are different on files we already have
 # found this is an update		
 # if we are using md5's then compare them
 # if we are yielding then the md5s are dif so
 # update the cached md5 value
 # this is a new file for our list. dont update the md5 here since
 # the file might not yet be done being written to

fileList
<not_specific>
alreadyExamined
<not_specific>
block
<not_specific>