diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/tool/rbuninstall.rb |
Fresh start
Diffstat (limited to 'jni/ruby/tool/rbuninstall.rb')
-rwxr-xr-x | jni/ruby/tool/rbuninstall.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/jni/ruby/tool/rbuninstall.rb b/jni/ruby/tool/rbuninstall.rb new file mode 100755 index 0000000..1a11766 --- /dev/null +++ b/jni/ruby/tool/rbuninstall.rb @@ -0,0 +1,67 @@ +#! /usr/bin/ruby -nl +BEGIN { + $dryrun = false + $tty = STDOUT.tty? + until ARGV.empty? + case ARGV[0] + when /\A--destdir=(.*)/ + $destdir = $1 + when /\A-n\z/ + $dryrun = true + when /\A--(?:no-)?tty\z/ + $tty = !$1 + else + break + end + ARGV.shift + end + $dirs = [] + $files = [] +} +list = ($_.chomp!('/') ? $dirs : $files) +$_ = File.join($destdir, $_) if $destdir +list << $_ +END { + status = true + $\ = ors = (!$dryrun and $tty) ? "\e[K\r" : "\n" + $files.each do |file| + print "rm #{file}" + unless $dryrun + begin + File.unlink(file) + rescue Errno::ENOENT + rescue + status = false + puts $! + end + end + end + unlink = {} + $dirs.each do |dir| + unlink[dir] = true + end + while dir = $dirs.pop + print "rmdir #{dir}" + unless $dryrun + begin + begin + unlink.delete(dir) + Dir.rmdir(dir) + rescue Errno::ENOTDIR + raise unless File.symlink?(dir) + File.unlink(dir) + end + rescue Errno::ENOENT, Errno::ENOTEMPTY + rescue + status = false + puts $! + else + parent = File.dirname(dir) + $dirs.push(parent) unless parent == dir or unlink[parent] + end + end + end + $\ = nil + print ors.chomp + exit(status) +} |