class RBT::RemoveSymlinks
Constants
- ARRAY_DIRECTORIES_TO_CHECK
#¶ ↑
ARRAY_DIRECTORIES_TO_CHECK
¶ ↑#¶ ↑
- DEFAULT_MODE
#¶ ↑
DEFAULT_MODE
¶ ↑#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
- SHALL_WE_CREATE_MISSING_DIRECTORIES
#¶ ↑
SHALL_WE_CREATE_MISSING_DIRECTORIES
¶ ↑This may create missing directories.
#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
consider_using_other_directories()
click to toggle source
#¶ ↑
consider_using_other_directories
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 171 def consider_using_other_directories case @mode when 'HERE','PWD','pwd' # This allows us to work on the current directory instead. @array_directories_to_check[0,0] = Dir.pwd end unless File.exist? @mode end
get_all_symlinks_from(i = Dir.pwd, be_verbose = true)
click to toggle source
#¶ ↑
get_all_symlinks_from
¶ ↑
This method will fetch and then return all symlinks from a given directory.
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 136 def get_all_symlinks_from(i = Dir.pwd, be_verbose = true) set_base_dir(i) _ = Dir[@base_dir+'*'].reject {|file| ! File.symlink? file} if be_verbose opnn; e "There are #{sfancy(_.size.to_s.rjust(3))} symlinks "+ "listed in "+sdir(i)+'.' end return _ end
notify_the_user_how_many_symlinks_were_removed()
click to toggle source
#¶ ↑
notify_the_user_how_many_symlinks_were_removed
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 149 def notify_the_user_how_many_symlinks_were_removed _ = @array_remove_these_broken_symlinks unless _.empty? opnn; e 'We were able to remove '+ orange(_.size.to_s)+ ' non-existing symlinks.' end end
process_each_directory( i = @array_directories_to_check )
click to toggle source
#¶ ↑
process_each_directory
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 100 def process_each_directory( i = @array_directories_to_check ) unless i.is_a? Array i = [i] end i.each {|entry| unless File.exist? entry if SHALL_WE_CREATE_MISSING_DIRECTORIES opnn; ewarn 'Directory `'+sdir(entry)+swarn('` does not exist.') opnn; ewarn 'Thus, we will create it now.' create_directory(entry) end end # ===================================================================== # # Next, obtain all symlinks from the target. # ===================================================================== # _ = get_all_symlinks_from(entry) _.each {|inner_entry| if File.exist? inner_entry # File exist, this is good, passthrough. else # The file does not exist, so register it for removal. # e 'FILE DOES NOT EXIST '+sfile(inner_entry) opnn; e sfile(inner_entry)+' does not exist.' opnn; e '-> Thus we delete `'+sfile(inner_entry)+'`.' register_broken_symlink_for_removal(inner_entry) # First register, then delete. end } } end
register_broken_symlink_for_removal(i)
click to toggle source
remove_all_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet )
click to toggle source
#¶ ↑
remove_all_symlinks
¶ ↑
This method will remove all symlinks in the current directory.
Invocation examples:
remove_symlinks --remove-all-symlinks remove_symlinks --pwd
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 258 def remove_all_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet ) _ = these_entries.select {|entry| File.symlink? entry } delete_symlink(_, be_verbose) end
Also aliased as: remove_these_symlinks
remove_broken_symlinks()
click to toggle source
#¶ ↑
remove_broken_symlinks
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 199 def remove_broken_symlinks if @array_remove_these_broken_symlinks.empty? opnn; e 'We did not find any broken symlinks on the system. '\ 'This is good!' else @array_remove_these_broken_symlinks.each {|this_symlink| # =================================================================== # # The reason we handle it in this class is so that we # can use opnn() on each removed symlink. # =================================================================== # opnn; delete_symlink(this_symlink, :be_verbose) } end end
remove_empty_directories()
click to toggle source
#¶ ↑
remove_empty_directories
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 161 def remove_empty_directories # ======================================================================= # # Delegate towards class RBT::RemoveEmptyDirectories next: # ======================================================================= # RemoveEmptyDirectories.new end
remove_these_symlinks( these_entries = Dir['*'], be_verbose = :be_quiet )
Alias for: remove_all_symlinks
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 71 def reset super() # Need to invoke the parent method here. @array_directories_to_check = ARRAY_DIRECTORIES_TO_CHECK @array_remove_these_broken_symlinks = [] @be_verbose = false @namespace = NAMESPACE end
run()
click to toggle source
set_base_dir(i)
click to toggle source
set_mode( i = DEFAULT_MODE )
click to toggle source
#¶ ↑
set_mode
¶ ↑
Not yet sure if we need this.
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 219 def set_mode( i = DEFAULT_MODE ) if i.is_a? Array i = i.first end i = DEFAULT_MODE if i.nil? case i # case tag # ======================================================================= # # === remove_symlinks --pwd # # This entry point will use the current working directory as our # input-base. # ======================================================================= # when /^-?-?pwd$/, /^-?-?remove(-|_)?all(-|_)?symlinks$/ remove_these_symlinks(Dir['*'], :be_verbose) exit # ======================================================================= # # === remove_symlinks --help # ======================================================================= # when /^-?-?help$/ show_help exit end @mode = i.to_s # Will be guaranteed to be a String. end
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
To invoke this method, try:
remove_symlinks --help
#¶ ↑
# File lib/rbt/utility_scripts/remove_symlinks.rb, line 186 def show_help opnn { :no_trailing_character } e e e ' --remove-all-symlinks # Remove all symlinks in '\ 'the current directory.' e ' --pwd # ^^^ an alias to the above' e end