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.
#¶ ↑
Public Class Methods
Public Instance Methods
are_the_two_target_directories_the_same_directory?()
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/cookbooks/find_duplicate_binaries.rb, line 199 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) }.sort 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 '+ steelblue('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/cookbooks/find_duplicate_binaries.rb, line 167 def do_delete_duplicate_files if delete_duplicates? and !@duplicate_files.empty? opne '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(i = sysbin_directory?)
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/cookbooks/find_duplicate_binaries.rb, line 235 def report_duplicate_files if found_duplicates? opne 'We have found these '+simp(@duplicate_files.size.to_s)+' '\ 'duplicates.' opne "They originate from the directory `#{sdir(ubin_dir?)}` and" opne 'are compared to the directory `'+sdir(sysbin_dir?)+'.' # ======================================================================= # # I am not sure why the code below exists; I assume I may have # wanted to show which entries are duplicates. But it is quite # spammy, so it was disabled on 25.05.2020. It may be re-enabled # at a later time, but then perhaps via a method call, and in # a slightly different formatted output, including colours. # But it may also be removed entirely instead - we will see. # 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 opne 'We did not find any duplicate entries. Thus, we will '\ 'do no further action.' end end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/cookbooks/find_duplicate_binaries.rb, line 60 def reset super() infer_the_namespace # ======================================================================= # # === @delete_duplicate_files # ======================================================================= # @delete_duplicate_files = DELETE_DUPLICATE_FILES end
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/find_duplicate_binaries.rb, line 270 def run menu # Check for the commandline-arguments first. report_to_the_user_what_we_will_do_next if are_the_two_target_directories_the_same_directory? opne 'The two directories are the same, so we can not '\ 'compare them -' opne 'it would make no sense.' else 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 end
set_input(i = '')
click to toggle source
show_help_options()
click to toggle source
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/cookbooks/find_duplicate_binaries.rb, line 222 def report_to_the_user_what_we_will_do_next opne 'We will compare all entries from '+ sdir(sysdir)+' with '\ 'entries from `'+ sdir(ubin_dir)+'`.' opne 'Duplicate entries will be reported.' end