2013-02-20 07:49:43 -05:00
|
|
|
#! /usr/bin/ruby -nl
|
|
|
|
BEGIN {
|
|
|
|
$dryrun = false
|
|
|
|
until ARGV.empty?
|
|
|
|
case ARGV[0]
|
|
|
|
when /\A--destdir=(.*)/
|
|
|
|
$destdir = $1
|
|
|
|
when /\A-n\z/
|
|
|
|
$dryrun = true
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
$dirs = []
|
|
|
|
$files = []
|
|
|
|
}
|
2013-03-12 22:09:18 -04:00
|
|
|
list = ($_.chomp!('/') ? $dirs : $files)
|
2013-02-20 07:49:43 -05:00
|
|
|
$_ = File.join($destdir, $_) if $destdir
|
|
|
|
list << $_
|
|
|
|
END {
|
|
|
|
status = true
|
|
|
|
if $dryrun
|
|
|
|
$files.each do |file|
|
|
|
|
puts "rm #{file}"
|
|
|
|
end
|
|
|
|
$dirs.reverse_each do |dir|
|
|
|
|
puts "rmdir #{dir}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
$files.each do |file|
|
|
|
|
begin
|
|
|
|
File.unlink(file)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
rescue
|
|
|
|
status = false
|
|
|
|
puts $!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$dirs.reverse_each do |dir|
|
|
|
|
begin
|
2013-03-08 00:24:23 -05:00
|
|
|
begin
|
|
|
|
Dir.rmdir(dir)
|
|
|
|
rescue Errno::ENOTDIR
|
|
|
|
raise unless File.symlink?(dir)
|
|
|
|
File.unlink(dir)
|
|
|
|
end
|
2013-02-20 07:49:43 -05:00
|
|
|
rescue Errno::ENOENT, Errno::ENOTEMPTY
|
|
|
|
rescue
|
|
|
|
status = false
|
|
|
|
puts $!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
exit(status)
|
|
|
|
}
|