Class: Setup::Uninstaller
Overview
TODO: It would be nice to improve this such that files to be removed are taken out of the list of directories that may be removed when they become empty. That way the end-user can see an exact list before commiting to the uninstall (using –force).
Instance Attribute Summary
Attributes inherited from Base
#config, #force, #io, #project, #quiet, #trace, #trial
Instance Method Summary collapse
Methods inherited from Base
#bash, #force?, #force_remove_file, #initialize, #initialize_hooks, #quiet?, #remove_file, #rm_f, #rmdir, #rootdir, #ruby, #trace?, #trace_off, #trial?
Constructor Details
This class inherits a constructor from Setup::Base
Instance Method Details
#uninstall ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/setup/uninstaller.rb', line 14 def uninstall return unless File.exist?(INSTALL_RECORD) files = [] dirs = [] paths.each do |path| dirs << path if File.dir?(path) files << path if File.file?(path) end if dirs.empty? && files.empty? io.outs "Nothing to remove." return end files.sort!{ |a,b| b.size <=> a.size } dirs.sort!{ |a,b| b.size <=> a.size } if !force? && !trial? puts (files + dirs).collect{ |f| "#{f}" }.join("\n") puts puts "Must use --force option to remove these files and directories that become empty." return end files.each do |file| rm_f(file) end dirs.each do |dir| entries = Dir.entries(dir) entries.delete('.') entries.delete('..') #begin rmdir(dir) if entries.empty? #rescue Errno::ENOTEMPTY # io.puts "not empty -- #{dir}" #end end rm_f(INSTALL_RECORD) end |