# File lib/rails-installer.rb, line 273
  def copy_files
    message "Checking for existing #{@@app_name.capitalize} install in #{install_directory}"
    files_yml = File.join(install_directory,'installer','files.yml')
    old_files = read_yml(files_yml) rescue Hash.new
    
    message "Reading files from #{source_directory}"
    new_files = sha1_hash_directory_tree(source_directory)
    new_files.delete('/config/database.yml') # Never copy this.
    
    # Next, we compare the original install hash to the current hash.  For each
    # entry:
    #
    # - in new_file but not in old_files: copy
    # - in old files but not in new_files: delete
    # - in both, but hash different: copy
    # - in both, hash same: don't copy
    #
    # We really should add a third hash (existing_files) and compare against that
    # so we don't overwrite changed files.

    added, changed, deleted, same = hash_diff(old_files, new_files)
    
    if added.size > 0
      message "Copying #{added.size} new files into #{install_directory}"
      added.keys.sort.each do |file|
        message " copying #{file}"
        copy_one_file(file)
      end
    end
    
    if changed.size > 0
      message "Updating #{changed.size} files in #{install_directory}"
      changed.keys.sort.each do |file|
        message " updating #{file}"
        copy_one_file(file)
      end
    end
    
    if deleted.size > 0
      message "Deleting #{deleted.size} files from #{install_directory}"
      
      deleted.keys.sort.each do |file|
        message " deleting #{file}"
        rm(File.join(install_directory,file)) rescue nil
      end
    end
    
    write_yml(files_yml,new_files)
  end