summaryrefslogtreecommitdiff
path: root/tool/rbuninstall.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tool/rbuninstall.rb')
-rwxr-xr-xtool/rbuninstall.rb36
1 files changed, 31 insertions, 5 deletions
diff --git a/tool/rbuninstall.rb b/tool/rbuninstall.rb
index f0c286012c..60f5241a4f 100755
--- a/tool/rbuninstall.rb
+++ b/tool/rbuninstall.rb
@@ -21,15 +21,33 @@ BEGIN {
end
$dirs = []
$files = []
+ COLUMNS = $tty && (ENV["COLUMNS"]&.to_i || begin require 'io/console/size'; rescue; else IO.console_size&.at(1); end)&.then do |n|
+ n-1 if n > 1
+ end
+ if COLUMNS
+ $column = 0
+ def message(str = nil)
+ $stdout.print "\b \b" * $column
+ if str
+ if str.size > COLUMNS
+ str = "..." + str[(-COLUMNS+3)..-1]
+ end
+ $stdout.print str
+ end
+ $stdout.flush
+ $column = str&.size || 0
+ end
+ else
+ alias message puts
+ end
}
list = ($_.chomp!('/') ? $dirs : $files)
list << $_
END {
status = true
$\ = nil
- ors = (!$dryrun and $tty) ? "\e[K\r" : "\n"
$files.each do |file|
- print "rm #{file}#{ors}"
+ message "rm #{file}"
unless $dryrun
file = File.join($destdir, file) if $destdir
begin
@@ -45,9 +63,10 @@ END {
$dirs.each do |dir|
unlink[dir] = true
end
+ nonempty = {}
while dir = $dirs.pop
dir = File.dirname(dir) while File.basename(dir) == '.'
- print "rmdir #{dir}#{ors}"
+ message "rmdir #{dir}"
unless $dryrun
realdir = $destdir ? File.join($destdir, dir) : dir
begin
@@ -58,16 +77,23 @@ END {
raise unless File.symlink?(realdir)
File.unlink(realdir)
end
- rescue Errno::ENOENT, Errno::ENOTEMPTY
+ rescue Errno::ENOTEMPTY
+ nonempty[dir] = true
+ rescue Errno::ENOENT
rescue
status = false
puts $!
else
+ nonempty.delete(dir)
parent = File.dirname(dir)
$dirs.push(parent) unless parent == dir or unlink[parent]
end
end
end
- print ors.chomp
+ message
+ unless nonempty.empty?
+ puts "Non empty director#{nonempty.size == 1 ? 'y' : 'ies'}:"
+ nonempty.each_key {|dir| print " #{dir}\n"}
+ end
exit(status)
}