# File lib/kwala/actions/code_duplication.rb, line 177
  def temporarily_remove_symlinks(dir)
    symlinks = Hash.new

    Find.find(dir) do |path|
      if File.symlink?(path)
        lnk = File.expand_path(path)

        # Need to give it relative to lnk
        src = File.expand_path(File.readlink(path), File.dirname(lnk))

        # Only remove symlinks that are relative to dir. i.e. inside
        # project to other parts of the project.

        if src.index(dir) == 0

          symlinks[lnk] = src

          # Store if it is a directory
          dircheck = File.directory?(path)

          # Remove the link
          FileUtils.rm_f(path)

          if dircheck
            # Prune must come after removing the file, because code
            # after prune will not run.
            Find.prune
          end

        end
      end
    end

    yield dir
  ensure

    symlinks.each do |sym, source|
      begin
        FileUtils.ln_s(source, sym)
      rescue => err
        STDERR.puts "Cannot restore link:", err
      end
    end
  end