Commit 4347e94a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Invalidate cache when files are renamed.

Take the file name also into account when calculating the MD5 hash
of a cache entry.  Otherwise files that are renamed would also be
read from cache, resulting in the old filename being referenced in
the docs and also in the warning messages.

Refs #446
parent 44e73fc8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ module JsDuck
          source = Util::IO.read(fname)
          docs = nil

          unless docs = cache.read(source)
          unless docs = cache.read(fname, source)
            docs = Parser.new.parse(source, fname, opts)
            cache.write(source, docs)
            cache.write(fname, source, docs)
          end

          {
+9 −9
Original line number Diff line number Diff line
@@ -36,10 +36,10 @@ module JsDuck
      FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
    end

    # Given contents of a source file, reads the already parsed data
    # structure from cache.  Returns nil when not found.
    def read(file_contents)
      fname = file_name(file_contents)
    # Given the name and contents of a source file, reads the already
    # parsed data structure from cache.  Returns nil when not found.
    def read(file_name, file_contents)
      fname = cache_file_name(file_name, file_contents)
      if File.exists?(fname)
        @previous_entry = fname
        File.open(fname, "rb") {|file| Marshal::load(file) }
@@ -50,9 +50,9 @@ module JsDuck
    end

    # Writes parse data into cache under a name generated from the
    # contents of a source file.
    def write(file_contents, data)
      fname = file_name(file_contents)
    # name and contents of a source file.
    def write(file_name, file_contents, data)
      fname = cache_file_name(file_name, file_contents)
      @previous_entry = fname
      File.open(fname, "wb") {|file| Marshal::dump(data, file) }
    end
@@ -70,8 +70,8 @@ module JsDuck

    private

    def file_name(file_contents)
      @cache_dir + "/" + md5(file_contents) + ".dat"
    def cache_file_name(file_name, file_contents)
      @cache_dir + "/" + md5(file_name + file_contents) + ".dat"
    end

    def md5(string)