class RBT::Cookbooks::FindDuplicateBinaries
Constants
- DELETE_DUPLICATE_FILES
#¶ ↑
DELETE_DUPLICATE_FILES
¶ ↑If this constant is true then we will also delete the duplicate binaries. This can be toggled by the user on the commandline.
By default, we will NOT delete the duplicate entries and this will also not be changed. The user specifically has to enable it on his/her own.
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
Public Instance Methods
comment(i)
click to toggle source
delete_duplicates?()
click to toggle source
detect_duplicate_files()
click to toggle source
#¶ ↑
detect_duplicate_files
¶ ↑
This will detect all duplicate files.
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 195 def detect_duplicate_files @duplicate_files = [] # Empty at the beginning. ubin_array = @usr_bin.map {|entry| File.basename(entry) }.sort sysbin_array = @system_executables.map {|entry| File.basename(entry) } counter = 0 # ======================================================================= # # Next, compare the ubin-array with the sysbin-array: # ======================================================================= # ubin_array.each {|entry| if sysbin_array.include? entry counter += 1 _ = ('('+simp(counter.to_s)+') ').rjust(20) e _+'Yes, '+slateblue(entry)+' is included. It is thus a duplicate.' @duplicate_files << entry end } @duplicate_files.sort! # And keep them sorted alphabetically. end
do_delete_duplicate_files()
click to toggle source
#¶ ↑
do_delete_duplicate_files
¶ ↑
This will delete only files in the /usr/bin/ hierarchy.
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 167 def do_delete_duplicate_files if delete_duplicates? and !@duplicate_files.empty? opnn; e 'Now deleting duplicate files from the '+sdir(ubin?)+ ' directory.' @duplicate_files.each {|entry| _ = sysbin?+File.basename(entry) if File.exist? _ # Extra safeguard here. e 'The file path at '+sfile(ubin?+entry)+' is a duplicate '\ 'of `'+sfile(File.readlink(_))+'`.' e 'Thus we can delete `'+sfile(ubin?+entry)+'`.' delete(ubin?+entry) # Delete it finally. end } end end
found_duplicates?()
click to toggle source
grab_files_from_system_index_bin()
click to toggle source
grab_files_from_usr_bin()
click to toggle source
input?()
click to toggle source
report_duplicate_files()
click to toggle source
#¶ ↑
report_duplicate_files
¶ ↑
This method will report whether we have duplicate files.
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 228 def report_duplicate_files if found_duplicates? opnn; e 'We have found these '+simp(@duplicate_files.size.to_s)+' '\ 'duplicates.' opnn; e "They originate from the directory `#{sdir(ubin_dir?)}` and" opnn; e 'are compared to the directory `'+sdir(sysbin_dir?)+'.' long_string = word_wrap( @duplicate_files.join(' ').strip, 62 ) long_string.chop! if long_string.end_with? ',' # Get rid of traling ','. e " #{long_string.strip}" else opnn; e 'We did not find any duplicate entries. Thus, we will '\ 'do no further action.' end end
reset()
click to toggle source
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 248 def run menu # Check for the commandline-arguments first. report_to_the_user_what_we_will_do_next grab_files_from_system_index_bin grab_files_from_usr_bin detect_duplicate_files report_duplicate_files do_delete_duplicate_files if delete_duplicates? end
set_input(i = '')
click to toggle source
show_help_options()
click to toggle source
#¶ ↑
show_help_options
(help tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 141 def show_help_options e 'Currently we support only one option:' e Colours.ecomment ' --delete # delete duplicate files found in '\ 'the '+sdir(ubin?)+comment(' hierarchy') # finddup --help e end
sysdir?()
click to toggle source
Private Instance Methods
report_to_the_user_what_we_will_do_next()
click to toggle source
#¶ ↑
report_to_the_user_what_we_will_do_next
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/find_duplicate_binaries.rb, line 217 def report_to_the_user_what_we_will_do_next opnn; e 'We will compare all entries from '+sdir(sysdir)+' with '\ 'entries from `'+sdir(ubin_dir)+'`.' opnn; e 'Duplicate entries will be reported.' end