summaryrefslogtreecommitdiff
path: root/tool/rbuninstall.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-13 07:24:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-13 07:24:48 +0000
commit6217307f436172aaa6ac466736913ba87f61575d (patch)
tree935b1f098261010effebd9fd21f10b9021633a96 /tool/rbuninstall.rb
parent80d8216415c3e42aab8237ef0b5696b488ecf387 (diff)
rbuninstall.rb: rmdir -p
* tool/rbuninstall.rb: remove parent directories. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/rbuninstall.rb')
-rwxr-xr-xtool/rbuninstall.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/tool/rbuninstall.rb b/tool/rbuninstall.rb
index 1d7f654..d04800b 100755
--- a/tool/rbuninstall.rb
+++ b/tool/rbuninstall.rb
@@ -20,15 +20,10 @@ $_ = File.join($destdir, $_) if $destdir
list << $_
END {
status = true
- if $dryrun
- $files.each do |file|
+ $files.each do |file|
+ if $dryrun
puts "rm #{file}"
- end
- $dirs.reverse_each do |dir|
- puts "rmdir #{dir}"
- end
- else
- $files.each do |file|
+ else
begin
File.unlink(file)
rescue Errno::ENOENT
@@ -37,9 +32,18 @@ END {
puts $!
end
end
- $dirs.reverse_each do |dir|
+ end
+ unlink = {}
+ $dirs.each do |dir|
+ unlink[dir] = true
+ end
+ while dir = $dirs.pop
+ if $dryrun
+ puts "rmdir #{dir}"
+ else
begin
begin
+ unlink.delete(dir)
Dir.rmdir(dir)
rescue Errno::ENOTDIR
raise unless File.symlink?(dir)
@@ -49,6 +53,9 @@ END {
rescue
status = false
puts $!
+ else
+ parent = File.dirname(dir)
+ $dirs.push(parent) unless parent == dir or unlink[parent]
end
end
end