What is the best way to determine which source files are no longer needed?


I am now responsible for a Rails application that was built in a very quick-and-dirty fashion. It has many view files (html templates) that are not used. It also has many css files that are not used.

What is the best way to determine which files are no longer needed so they can be deleted?

I'm looking for a generic solution and not a Rails-specific solution, but a Ruby/Rails-only solution will definitely be welcomed.

Just to get things started, one idea I had (which I'm not particularly fond of) for determining which views were used is as follows:

  1. Write a script that will insert a line of code into the top of every view file. The line of code will append the name of the view to some sort of log.
  2. Recursively wget the entire site
  3. Go through the log and remove duplicates - then we have a list of views that are used
  4. Delete views that are not listed in the log

If you are on a unix-like system:

Make sure the partition with the pages are mounted with access time (atime) enabled. On linux, mounts with relatime or noatime will not help you.)

Pick the current time.

Run the webserver for a few days.

Identify files whose atime is older than the previously picked time. They are not being used.