2013-02-20 16:49:43 +04:00
|
|
|
#! /usr/bin/ruby -nl
|
2016-07-03 00:01:04 +03:00
|
|
|
|
|
|
|
# Used by the "make uninstall" target to uninstall Ruby.
|
|
|
|
# See common.mk for more details.
|
|
|
|
|
2013-02-20 16:49:43 +04:00
|
|
|
BEGIN {
|
|
|
|
$dryrun = false
|
2013-09-13 11:28:23 +04:00
|
|
|
$tty = STDOUT.tty?
|
2013-02-20 16:49:43 +04:00
|
|
|
until ARGV.empty?
|
|
|
|
case ARGV[0]
|
|
|
|
when /\A--destdir=(.*)/
|
|
|
|
$destdir = $1
|
|
|
|
when /\A-n\z/
|
|
|
|
$dryrun = true
|
2013-09-13 11:28:23 +04:00
|
|
|
when /\A--(?:no-)?tty\z/
|
|
|
|
$tty = !$1
|
2013-02-20 16:49:43 +04:00
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
$dirs = []
|
|
|
|
$files = []
|
|
|
|
}
|
2013-03-13 06:09:18 +04:00
|
|
|
list = ($_.chomp!('/') ? $dirs : $files)
|
2013-02-20 16:49:43 +04:00
|
|
|
list << $_
|
|
|
|
END {
|
|
|
|
status = true
|
2020-05-08 19:40:40 +03:00
|
|
|
$\ = nil
|
|
|
|
ors = (!$dryrun and $tty) ? "\e[K\r" : "\n"
|
2013-09-13 11:24:48 +04:00
|
|
|
$files.each do |file|
|
2020-05-08 19:40:40 +03:00
|
|
|
print "rm #{file}#{ors}"
|
2013-09-13 11:28:23 +04:00
|
|
|
unless $dryrun
|
2020-05-09 07:45:50 +03:00
|
|
|
file = File.join($destdir, file) if $destdir
|
2013-02-20 16:49:43 +04:00
|
|
|
begin
|
|
|
|
File.unlink(file)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
rescue
|
|
|
|
status = false
|
|
|
|
puts $!
|
|
|
|
end
|
|
|
|
end
|
2013-09-13 11:24:48 +04:00
|
|
|
end
|
|
|
|
unlink = {}
|
|
|
|
$dirs.each do |dir|
|
|
|
|
unlink[dir] = true
|
|
|
|
end
|
|
|
|
while dir = $dirs.pop
|
2020-05-08 19:43:53 +03:00
|
|
|
dir = File.dirname(dir) while File.basename(dir) == '.'
|
2020-05-08 19:40:40 +03:00
|
|
|
print "rmdir #{dir}#{ors}"
|
2013-09-13 11:28:23 +04:00
|
|
|
unless $dryrun
|
2020-05-09 07:45:50 +03:00
|
|
|
realdir = $destdir ? File.join($destdir, dir) : dir
|
2013-02-20 16:49:43 +04:00
|
|
|
begin
|
2013-03-08 09:24:23 +04:00
|
|
|
begin
|
2013-09-13 11:24:48 +04:00
|
|
|
unlink.delete(dir)
|
2020-05-09 07:45:50 +03:00
|
|
|
Dir.rmdir(realdir)
|
2013-03-08 09:24:23 +04:00
|
|
|
rescue Errno::ENOTDIR
|
2020-05-09 07:45:50 +03:00
|
|
|
raise unless File.symlink?(realdir)
|
|
|
|
File.unlink(realdir)
|
2013-03-08 09:24:23 +04:00
|
|
|
end
|
2013-02-20 16:49:43 +04:00
|
|
|
rescue Errno::ENOENT, Errno::ENOTEMPTY
|
|
|
|
rescue
|
|
|
|
status = false
|
|
|
|
puts $!
|
2013-09-13 11:24:48 +04:00
|
|
|
else
|
|
|
|
parent = File.dirname(dir)
|
|
|
|
$dirs.push(parent) unless parent == dir or unlink[parent]
|
2013-02-20 16:49:43 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-13 11:28:23 +04:00
|
|
|
print ors.chomp
|
2013-02-20 16:49:43 +04:00
|
|
|
exit(status)
|
|
|
|
}
|