[Rake-devel] FileTask#needed? and FileTask#timestamp "bug"

philipp.neubeck at gmx.de philipp.neubeck at gmx.de
Sun Sep 4 05:19:50 EDT 2005

Hi there,

think of the following situation:

file "foo"
file "bar" => [ "foo" ]

file "foo" does NOT exist, while "bar" does, then the timestamp method of bar's FileTask raises an unhandeled (not handeled by Rake) exception ('file not found...'), because it is called by "foo"'s FileTask#needed?.

i think there shouldn't be any exception thrown in this situation, but "bar" rebuild. if "bar" did not exist then "bar" would also be rebuild, so why not in this case. so my patch would be:

class FileTask
  def needed?
    return true unless File.exist?(name)
    @prerequisites.each{|n| return true if Task[n].timestamp >= timestamp }
    return false
  rescue Errno::ENOENT => ex # one of the prereqs does not exist
    raise unless $dryrun or $trace

  def timestamp
    return Time.now unless File.exist?( name )

i also removed the collect{}.max. if one want's to check if the prerequisites exist, then do that but don't calculate a maximum, which is unneeded.
if it is supposed that 'needed?' is mainly called by Task#invoke then the checking should be there (see Task#invoke, it iterates the @prerequ..s already) and not here

hope it helps,


More information about the Rake-devel mailing list