#!/usr/bin/ruby require 'fileutils' require 'find' $replaceOriginal = false $replaceOriginal = true if ARGV[0] == "replace" #puts $replaceOriginal TMP_FILE='/tmp/kdefix234.txt' FIRST = ?[ PATTERN = FIRST + ?f + ?i + ?] def fixFile(toFix) f = File.new(toFix, 'r') outFile = File.new(TMP_FILE, 'w') tomatch = 0 byte = 0 corrupted = false while byte = f.getc if byte == FIRST tomatch = byte outFile.putc byte 3.times { if byte = f.getc tomatch += byte outFile.putc byte end } if tomatch == PATTERN while (byte = f.getc) != ?\n && byte #puts byte.chr #puts byte if byte == 239 && f.getc == 191 && f.getc == 189 corrupted = true #output a with dots outFile.putc 195 outFile.putc 164 else outFile.putc byte end end outFile.puts end else outFile.putc byte end end f.close outFile.close if corrupted then print toFix, ' is corrupted' if $replaceOriginal print ' --> fixing' FileUtils.cp(TMP_FILE, toFix) end puts end end if( ($replaceOriginal && ARGV.length > 1) || (! $replaceOriginal && ARGV.length > 0)) puts 'Using filenames given in command line' ARGV.each { |name| #name.match(/(desktop)|(directory)$/) && if FileTest.file?(name) fixFile(name) end } else if ! $replaceOriginal puts 'Searching /usr/kde/3.4 for corrupted files' else puts 'Fixing non executable files in /usr/kde/3.4' end Find.find('/usr/kde/3.4/') { |name| if FileTest.file?(name) && ! FileTest.executable?(name) fixFile(name) end } end File.exist?(TMP_FILE) && FileUtils.rm(TMP_FILE)